interface Table

Table definition with CRUD operations

Type Parameters

Row
Input

Properties

columns: readonly string[]

Physical DB columns declared for this table, in schema order.

deleteById: (id: InValue) => Promise<void>

Delete a row by primary key

findAll: () => Promise<Row[]>

Find all rows

findById: (id: InValue) => Promise<Row | null>

Find a row by primary key, or null when it does not exist.

optional
findByIdPrimary: (id: InValue) => Promise<Row | null>

Find a row by primary key, pinned to the primary (read-your-writes). Use when reading a row back immediately after committing its own write: a plain findById runs in "read" mode, which Turso may serve from a replica that lags behind the just-committed write and so miss the row (returning null). This reads on the primary, which always reflects the write.

Optional, like insertStatement/updateStatement: only the transactional CRUD-side-effect write path reads a row back this way, so a façade table that never takes that path may omit it.

findByIds: (ids: InValue[]) => Promise<(Row | null)[]>

Find rows in input order, retaining nulls for missing primary keys.

fromDb: (row: Row) => Promise<Row>

Transform a row from DB (apply read transforms)

inputKeyMap: Record<string, string>
insert: (input: Input) => Promise<Row>

Insert a new row, returns the created row

optional
insertStatement: (
input: Input,
condition?: SqlStatement,
) => Promise<SqlStatement>

Build the INSERT statement without executing it (for transactional callers). Optional: only resources with a CRUD side effect need it; façade tables omit it.

name: string
primaryKey: keyof Row & string
rowToInput: (
row: Row,
exclude?: readonly string[],
) => Partial<Input>

Build an Input object from an existing Row by copying the input-eligible columns and translating keys through inputKeyMap. Lets callers spread a row into a new insert without restating every field. Columns named in exclude are skipped — useful for auto-stamped fields like created.

toDbValues: (input: Input | Partial<Input>) => Promise<Record<string, InValue>>

Transform input to DB values (apply write transforms and defaults)

update: (
id: InValue,
input: Partial<Input>,
) => Promise<Row | null>

Update a row by primary key, returns updated row or null if not found

optional
updateStatement: (
id: InValue,
input: Partial<Input>,
condition?: SqlStatement,
) => Promise<SqlStatement>

Build the UPDATE statement without executing it (input must provide ≥1 column). Optional: see insertStatement.