GizStack
View .mdOpen in ChatGPTOpen in Claude

gizmodel/insert

the INSERT of a stored Model.Shape's records, as the tree every engine runs. A typed store (model/data.giz) and a SQL store's copy (model/store.giz) build it here; model/query.giz gives its names again.

gizlang
import * as Insert from "gizmodel/insert";

Types

Existing

gizlang
type Existing = | { kind: "refuse"; } | { kind: "keep"; } | { kind: "replace"; } | { kind: "add"; }

What an INSERT does with a row whose key is there already: refuse it (a conflict), keep the stored row, replace it, or add it: each numeric field holds the sum of the stored and the new value, each other field the new value.

  • refuse
  • keep
  • replace
  • add

Insertion

gizlang
type Insertion = { statement: Tree.Statement; params: Vec<Value>; }

An INSERT and the values of its parameters $1.., row by row in field order.

  • statement: M151.Statement
  • params: Vec<M143.Value>

Functions

insertion

gizlang
function insertion(shape: Model.Shape, rows: Vec<Vec<Value>>, existing: Existing): Insertion throws DbError

The INSERT of ROWS of SHAPE (each one value per field, in field order; a computed field's is left out), which does EXISTING with a row whose key is there.

Effects: fail, alloc.

loading

gizlang
function loading(shape: Model.Shape, load: Batch, existing: Existing): Tree.Statement throws DbError

The INSERT of the records in LOAD (Model.loadOf: a column for each stored field) into SHAPE's table, for an engine: it stores the columns as they are. EXISTING is as insertion takes it.

Effects: fail, alloc.