interface Table

Table definition with CRUD operations

Type Parameters

Row
Input

Properties

name: string
primaryKey: keyof Row & string
inputKeyMap: Record<string, string>
insert: (input: Input) => Promise<Row>

Insert a new row, returns the created row

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

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

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

Find a row by primary key

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

Delete a row by primary key

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

Find all rows

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

Transform a row from DB (apply read transforms)

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

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