gizmodel/sql/render
The one place the DAL prints a syntax tree as SQL text of a dialect: external pushdown, the SQL stores of gizmodel/store and gizmodel/data, and the views of gizweb/view. Each construct is checked for the dialect; one that has no verified representation is reported, never changed to an approximate execution. bound keeps values out of the text: each literal value but NULL, a boolean and an integer goes to the client as a parameter.
import * as Render from "gizmodel/sql/render";Types
Rendered
type Rendered = { sql: string; parameters: Vec<i64>; }SQL text with ? placeholders, and for each placeholder in order the index of the value it takes: a parameter
$N takes value N-1; with bound, a literal takes the value after the given ones (Bound).
sql:stringparameters:Vec<i64>
Bound
type Bound = { sql: string; values: Vec<Value>; }SQL text and the values its placeholders take, in order.
sql:stringvalues:Vec<M143.Value>
Functions
render
function render(q: Select, dialect: string): Rendered throws DbErrorQ as SQL of DIALECT with its literals written in the text.
Effects: fail, alloc.
mutation
function mutation(command: Statement, dialect: string): Rendered throws DbErrorCOMMAND (INSERT of rows or of a query, UPDATE, DELETE) as SQL of DIALECT with its literals written in the text.
Effects: fail, alloc.
bound
function bound(q: Select, dialect: string, given: Vec<Value>, numbered: bool): Bound throws DbErrorQ as SQL of DIALECT for a client that binds its parameters $1.. to GIVEN and every other value the text would hold (Bound): no text or bytes are spliced into SQL. NUMBERED writes the placeholders $1, $2, ... (PostgreSQL, SQLite); else each is ?.
Effects: fail, alloc.
boundMutation
function boundMutation(command: Statement, dialect: string, given: Vec<Value>, numbered: bool): Bound throws DbErrorCOMMAND as SQL of DIALECT with its values bound, as bound.
Effects: fail, alloc.
expressionText
function expressionText(e: Expr, dialect: string, isCondition: bool = false): string throws DbErrorE as SQL text of DIALECT with its literals written in: where a condition stands when CONDITION, else as a value.
Effects: fail, alloc.
boundCondition
function boundCondition(e: Expr, dialect: string, first: i64): Bound throws DbErrorThe condition E as SQL of DIALECT with its values bound and its placeholders numbered from $FIRST: for the SQL text the DAL writes around a typed condition (the copies of store.giz).
Effects: fail, alloc.