gizweb:table
the typed table of a page. A route file declares const todos = table<Todo>("created desc"); and reads and writes it as the records of its type; the generated code calls this module. Every read and write goes through Data and its Gate, so a page shows and changes only what the person who asks may. The SQL of where and count is made at build time from the lambda; every value in it is a parameter, so a value cannot become SQL.
import * as Table from "gizweb:table";Types
Meter
type Meter = { fault: Task.Cell<Model.Rejection>; reads: Task.Atomic; writes: Task.Atomic; counted: Task.Cell<Vec<Counted>>; }What a request of a page leaves in its tables: the first refusal or failure (the status and reason of the answer; 200 when none), and how many reads and writes it made. A page reads a table as a list, so a failed read cannot be a value of the list: it is kept here, and the host answers with it instead of a list that looks empty.
fault:gizlang_task.Cell<M48.Rejection>reads:gizlang_task.Atomicwrites:gizlang_task.Atomiccounted:gizlang_task.Cell<Vec<M68.Counted>>
Focus
type Focus = { mode: Task.Atomic; only: Task.Atomic; table: string; keys: Vec<Value>; out: Option<Task.Cell<Patches.Patch>> }What a live request of a page asks (web/region.giz): the table that changed and the keys of its rows that changed (none: any row may have), the
patches that the ranges of the page made, and two switches. mode is 1 while the page is looked through for the ranges that read the table
(nothing else is rendered), 0 while a range renders. only is 1 while the reads of the table are limited to the rows of those keys. An
ordinary request has no patches (out is none) and its mode is 0.
mode:gizlang_task.Atomiconly:gizlang_task.Atomictable:stringkeys:Vec<M55.Value>out:_gizlang_sdk_core.Option<gizlang_task.Cell<_gizlang_lib_web__html.Patch>>
Context
type Context = { scoped: Option<Data.Scoped>; sys: System; me: string; live: bool; meter: Meter; focus: Focus; }What a page needs of its host: the records as the person who asks may use them (none when the host has no database), who that is, and whether the
client runs the kernel (live: only such a client polls, so only it gets a watch).
scoped:_gizlang_sdk_core.Option<M49.Scoped>sys:gizlang_system.Systemme:stringlive:boolmeter:M68.Meterfocus:M68.Focus
Table
type Table<T> = { context: Context; shape: Model.Shape; order: string; orderText: string; }The records of type T that the person may read and write; ORDER is the ORDER BY of every read.
Opaque: create and use it through this module's functions.
Functions
meter
function meter(): MeterA meter of one request: no fault, no reads, no writes.
Effects: fail, io.
quiet
function quiet(): FocusThe focus of an ordinary request.
Effects: io.
seeking
function seeking(table: string, keys: Vec<Value>): FocusThe focus of the request that tells a page of the change of the rows KEYS of the table TABLE.
Effects: fail, io.
context
function context(scoped: Option<Data.Scoped>, sys: System, me: string, live: bool): ContextThe context of an ordinary request.
Effects: fail, io.
table
function table<T>(context: Context, order: string): Table<T>The table of T, ordered by ORDER (field names, each with asc or desc: "created desc, id"; empty is by key).
tailOf
function tailOf(shape: Model.Shape, order: string, limit: i64): stringThe ORDER BY and LIMIT of a read, from field names that the Shape holds. A name it does not hold is a defect of the page.
Effects: fail.
keyText
function keyText(key: Value): Option<string>The text of a key value as a page writes it (the data-k of a row), or none for a type that a key text cannot stand for.
Effects: fail.
rowsGrid
function rowsGrid(names: Vec<string>, rows: Vec<Vec<Option<string>>>): HtmlA query's answer as a read-only grid(): a column for each of NAMES, a row for each of ROWS, a NULL cell data-null.
Effects: fail.
like
function like(value: string, before: bool, after: bool): stringThe text of LIKE for a value that a text contains (BEFORE and AFTER), starts (AFTER) or ends with (BEFORE): % and _ in the value are no wildcards.
Effects: fail.
withKeys
function withKeys(shape: Model.Shape, sys: System, fields: Model.Fields): Model.FieldsFIELDS with a made key for each text key of SHAPE that is missing.
Effects: fail, io.
Methods
Table.key
function Table.key<T>(self: Table<T>, v: T): stringThe key of a record as text (its first key field), or empty.
Table.rows
function Table.rows<T>(self: Table<T>): Vec<T>All the records, in the order of the table.
Table.where
function Table.where<T>(self: Table<T>, sql: string, fields: Vec<string>, wires: Vec<string>, order: string, limit: i64): Vec<T>The records that a condition selects: SQL over the columns, $1.. its parameters; FIELDS[i] is the field that WIRES[i] is the value of
(empty when WIRES[i] is true or false, the value of a part of the condition that names no field). ORDER is the order of this read (empty
is the order of the table) and LIMIT its most rows (0 is the most a page reads).
Table.count
function Table.count<T>(self: Table<T>, sql: string, fields: Vec<string>, wires: Vec<string>): i64How many records a condition selects, counted by the database.
Table.total
function Table.total<T>(self: Table<T>): i64How many records the table holds that the person may read.
Table.grid
function Table.grid<T>(self: Table<T>): HtmlThe rows of the table as a <giz-grid> around an HTML <table>: a column for each field that is not hidden, headed by its label
(data-field its name), each cell the field as a person reads it (Model.display). A row is data-k its key, so a page that reads the
table with grid() is a range that renders again whole on a change. With the giz-grid enhancement (web/components/src/grid.js), RevoGrid
Pro shows the same table: sort, filter, select, copy, export.
Table.editableGrid
function Table.editableGrid<T>(self: Table<T>, name: string): Htmlgrid() whose cells of the fields that are not keys are bound controls of the page (_f.NAME.field.key, with _o. what the cell
showed), as value={t.field} in an each: a change is one update of that field through the Gate, and a field that another person changed
meanwhile is a conflict. Without script the grid is a form of the page; with the enhancement, an edit, a paste or a fill in RevoGrid
changes these controls. NAME is the table's name in the page (the GHTML compiler gives it).
Table.add
function Table.add<T>(self: Table<T>, v: T): stringAdd the record V; a text key that is empty is made.
Table.create
function Table.create<T>(self: Table<T>, posted: Http.Params, prefix: string): stringAdd the record that a form posted: the controls PREFIX + field of the posted fields.
Table.set
function Table.set<T>(self: Table<T>, v: T): stringReplace the record with the key of V by V.
Table.remove
function Table.remove<T>(self: Table<T>, v: T): stringDelete the record with the key of V.
Table.removeWhere
function Table.removeWhere<T>(self: Table<T>, sql: string, fields: Vec<string>, wires: Vec<string>): stringDelete every record that a condition selects, as where selects them: it stops at the first refusal and gives its reason. A pass reads at most
MOST_ROWS records, so it reads again until none is left.
Table.apply
function Table.apply<T>(self: Table<T>, name: string, posted: Http.Params): stringThe changes that the page posted for the table NAME, as _f.NAME.field.key = value, in the order posted (the last value of a control counts).
_o. + the same name is what the control showed: a control that shows what it posts did not change, and a change whose old value is gone is a conflict.
Table.watch
function Table.watch<T>(self: Table<T>): HtmlThe element that keeps a page current: the kernel long-polls the changes of the table (a watch on all its rows; the host tells a person only the changes of rows the person may read, Pages told) and gets
the page again when one comes. Nothing leaves the server but that a change happened; the page reads its rows again under the same grants.