Home Reference Source
public class | source

SqliteContext

Extends:

Context → SqliteContext

Constructor Summary

Public Constructor
public

Member Summary

Private Members
private

_db: *

Method Summary

Public Methods
public

async compile(cell: *, expr: boolean): *

Compile a cell

public

async execute(cell: *, expr: boolean): *

Execute a cell

public

async outputs(): *

Get a list of outputs available from this context

public

async provide(what: *): *

An override to provide the caller an output value (in this context's case, a database table) as a data package

public

async resolve(what: *): {"local": boolean, "table": *}

Resolve an output value

Private Methods
private

_appendError(node: *, error: *): *

Handle an error when compiling or executing a node including dealing with error locations

private

Do string interpolation of variables in SQL code

private

async _pack(name: *, select: *, node: *): *

private

_tableInputs(ast: AST): Array

Get table inputs by filtering the AST but exclude those tables that already exist in the database

private

_transpileSql(sql: *): {"output": *, "sql": *}

Transpile SQL removing any output = SELECT ... extensions and returning the output names

private

async _unpack(input: Object): Object

Unpack an input {name, value} object

Inherited Summary

From class Context
public get

host: *

public get

id: *

public get

location: {"context": *, "host": *, "machine": *}

public get

name: *

private

_host: *

private
private

_name: *

private
public

async compile(cell: *): {"source": *, "expr": *, "global": *, "options": *, "inputs": *, "outputs": *, "messages": *}

public

async evaluate(node: *): *

public

async execute(cell: *): *

public

async libraries(): {}

public

async pack(value: *): *

public

async packPackage(value: *): {"type": *, "data": *}

public

async packPointer(objectPattern: {"type": *, "name": *, "preview": *}): {"type": *, "path": *, "preview": *}

public

async provide(what: *): *

public

async resolve(what: *): *

public

async unpack(node: Object): [type]

Unpack a data node into a native data value

public

async unpackPackage(pkg: *): *

public

async unpackPointer(pointer: *): *

Public Constructors

public constructor() source

Override:

Context#constructor

Private Members

private _db: * source

Public Methods

public async compile(cell: *, expr: boolean): * source

Compile a cell

For a cell with expr=true, checks that the node consists of a single SELECT statement. That is, multiple SELECT statements, or other types of SQL statements, e.g UPDATE, DELETE, are invalid.

Parses SQL to determine the inputs property of the node including variable interpolations and tables e.g. SELECT * FROM data WHERE height > ${min_height} creates the inputs ["min_height", "data"]. Note that if a table already exists in the database then it is not included in inputs since it does not need to be provided by the execution engine

For expr=false (block) nodes determines if there is an output e.g low_gravity_planets in low_gravity_planets = SELECT * FROM planets WHERE gravity <= 1

Checks for any statements that may cause side effects e.g DELETE or CREATE TABLE statements

Override:

Context#compile

Params:

NameTypeAttributeDescription
cell *
expr boolean
  • optional
  • default: false

Return:

*

public async execute(cell: *, expr: boolean): * source

Execute a cell

Override:

Context#execute

Params:

NameTypeAttributeDescription
cell *
expr boolean
  • optional
  • default: false

Return:

*

public async outputs(): * source

Get a list of outputs available from this context

Return:

*

public async provide(what: *): * source

An override to provide the caller an output value (in this context's case, a database table) as a data package

Override:

Context#provide

Params:

NameTypeAttributeDescription
what *

Return:

*

public async resolve(what: *): {"local": boolean, "table": *} source

Resolve an output value

Override:

Context#resolve

Params:

NameTypeAttributeDescription
what *

Return:

{"local": boolean, "table": *}

Private Methods

private _appendError(node: *, error: *): * source

Handle an error when compiling or executing a node including dealing with error locations

Params:

NameTypeAttributeDescription
node *
error *

Return:

*

private _interpolateSql(sql: String): Object source

Do string interpolation of variables in SQL code

Params:

NameTypeAttributeDescription
sql String

SQL code with interpolation marks e.g. SELECT * FROM data WHERE height > ${x} AND width < ${y}

Return:

Object

Interpolation variable names and interpolated e.g. {variables:['x', 'y'], sql: 'SELECT * FROM data WHERE height > 10 AND width < 32'}

private async _pack(name: *, select: *, node: *): * source

Params:

NameTypeAttributeDescription
name *
select *
node *

Return:

*

private _tableInputs(ast: AST): Array source

Get table inputs by filtering the AST but exclude those tables that already exist in the database

Params:

NameTypeAttributeDescription
ast AST

SQL AST

Return:

Array

A list of tables that are inputs into the SQL statement/s

private _transpileSql(sql: *): {"output": *, "sql": *} source

Transpile SQL removing any output = SELECT ... extensions and returning the output names

Params:

NameTypeAttributeDescription
sql *

Return:

{"output": *, "sql": *}

private async _unpack(input: Object): Object source

Unpack an input {name, value} object

Params:

NameTypeAttributeDescription
input Object

Input object

Return:

Object

Object with name and unpacked value {name, value}