# 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.

```gizlang
import * as Render from "gizmodel/sql/render";
```

## Types

### `Rendered`

```gizlang
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`: `string`
- `parameters`: `Vec<i64>`

### `Bound`

```gizlang
type Bound = { sql: string; values: Vec<Value>; }
```

SQL text and the values its placeholders take, in order.

- `sql`: `string`
- `values`: `Vec<M143.Value>`

## Functions

### `render`

```gizlang
function render(q: Select, dialect: string): Rendered throws DbError
```

Q as SQL of DIALECT with its literals written in the text.

Effects: fail, alloc.

### `mutation`

```gizlang
function mutation(command: Statement, dialect: string): Rendered throws DbError
```

COMMAND (INSERT of rows or of a query, UPDATE, DELETE) as SQL of DIALECT with its literals written in the text.

Effects: fail, alloc.

### `bound`

```gizlang
function bound(q: Select, dialect: string, given: Vec<Value>, numbered: bool): Bound throws DbError
```

Q 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`

```gizlang
function boundMutation(command: Statement, dialect: string, given: Vec<Value>, numbered: bool): Bound throws DbError
```

COMMAND as SQL of DIALECT with its values bound, as `bound`.

Effects: fail, alloc.

### `expressionText`

```gizlang
function expressionText(e: Expr, dialect: string, isCondition: bool = false): string throws DbError
```

E as SQL text of DIALECT with its literals written in: where a condition stands when CONDITION, else as a value.

Effects: fail, alloc.

### `boundCondition`

```gizlang
function boundCondition(e: Expr, dialect: string, first: i64): Bound throws DbError
```

The 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.

