SqliteContext
Extends:
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Private Members | ||
private |
_db: * |
Method Summary
Public Methods | ||
public |
Compile a cell |
|
public |
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 |
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 |
_interpolateSql(sql: String): Object 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 |
|
private |
Unpack an input |
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 |
_variables: {} |
|
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 |
Unpack a data node into a native data value |
|
public |
async unpackPackage(pkg: *): * |
|
public |
async unpackPointer(pointer: *): * |
Public Constructors
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#compileParams:
Name | Type | Attribute | Description |
cell | * | ||
expr | boolean |
|
Return:
* |
public async execute(cell: *, expr: boolean): * source
Execute a cell
Override:
Context#executeParams:
Name | Type | Attribute | Description |
cell | * | ||
expr | boolean |
|
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#provideParams:
Name | Type | Attribute | Description |
what | * |
Return:
* |
public async resolve(what: *): {"local": boolean, "table": *} source
Resolve an output value
Override:
Context#resolveParams:
Name | Type | Attribute | Description |
what | * |
Private Methods
private _appendError(node: *, error: *): * source
Handle an error when compiling or executing a node including dealing with error locations
Params:
Name | Type | Attribute | Description |
node | * | ||
error | * |
Return:
* |
private _interpolateSql(sql: String): Object source
Do string interpolation of variables in SQL code
Params:
Name | Type | Attribute | Description |
sql | String | SQL code with interpolation marks e.g. |
Return:
Object | Interpolation variable names and interpolated e.g. |
private async _pack(name: *, select: *, node: *): * source
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
ast | AST | SQL AST |
private _transpileSql(sql: *): {"output": *, "sql": *} source
Transpile SQL removing any output = SELECT ...
extensions and
returning the output names
Params:
Name | Type | Attribute | Description |
sql | * |
Return:
{"output": *, "sql": *} |