Skip to content
velt/db exports

velt/db

API reference

What database drivers share: typed rows from any source of tabular data, and a statement's parameters handed to a native driver. The SQLite and PostgreSQL packages read their rows this way, so a typed query there (stmt.all<User>()) fills its Users by the rules on this page. For a walkthrough, read the guide.

import { readRows, RowSource, CellKind, RowError } from "velt/db";

Exports

function

decodeRow

#std/db/native.vlt:41

Re-exported from velt/db/native

function decodeRow<T>(cursor: u64): T

The one row of a native driver's row cursor opened for a single row, as a T (see decodeRows). Throws RowError for a row that does not fit T, and for a handle that names no open row cursor.

function

decodeRows

#std/db/native.vlt:27

Re-exported from velt/db/native

function decodeRows<T>(cursor: u64): T[]

Every row of a native driver's row cursor (its handle) as a T: each column fills the field of its name, as readRows fills them from a RowSource (the same conversions and messages). The cursor stays the driver's: give the handle back to the driver afterwards, which then reports a failure met while stepping. Throws RowError for a row that does not fit T, and for a handle that names no open row cursor.

function

bindParams

#std/db/native.vlt:59

Re-exported from velt/db/native

function bindParams<P>(sink: u64, params: P): bool

Hands params to a native driver's parameter sink (its handle) value by value: an array, a tuple or a lone value by position, an object's fields by name, each value bound as its JSON text would read back (an integral number an integer, NaN null, a u8[] field a blob). True once they went to the sink; false, having done nothing, for a type it cannot take that way (a nested object, a union): the driver then takes JSON.stringify(params) instead, which binds the same values. False too for a handle that names no open parameter sink (nothing reaches memory; the driver finds the handle dead when it is handed on).

function

readRow

#std/db/read.vlt:35

Re-exported from velt/db/read

function readRow<T, S extends RowSource>(src: S): T | null

The next row of src as a T, or null when there is none. Throws RowError as readRows does.

function

readRows

#std/db/read.vlt:18

Re-exported from velt/db/read

function readRows<T, S extends RowSource>(src: S): T[]

Every remaining row of src as a T. Throws RowError for a row that does not fit, and with the message of what the source's methods throw.

Re-exported from velt/db/errors

class RowError extends Error

A row that does not fit the requested type (expected i64 at $[0].id).

constructor(message: string)No doc comment yet
interface

RowSource

#std/db/row_source.vlt:22

Re-exported from velt/db/row_source

Rows as a driver produces them: their columns, and the current row's values by column. The reader asks each value's kind before taking it with the getter of that kind.

columnCount(): i64

The number of columns.

columnName(i: i64): string

The name of column i (from 0): the field it fills.

next(): bool

Moves to the next row (the first on the first call): false when there is none.

kind(i: i64): CellKind

What column i of the current row holds.

bool(i: i64): boolNo doc comment yet
int(i: i64): i64No doc comment yet
float(i: i64): f64No doc comment yet
text(i: i64): stringNo doc comment yet
blob(i: i64): u8[]No doc comment yet
json(i: i64): stringNo doc comment yet

Re-exported from velt/db/row_source

What a column of the current row holds.

NullNo doc comment yet
BoolNo doc comment yet
IntNo doc comment yet
FloatNo doc comment yet
Text

Text (UTF-8).

Blob

Bytes, a u8[].

Json

A nested value (an array or object) as its JSON text.