Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0053-sql-typed FR-007
Typed statements (commons data 0053-sql-typed): insertInto, update and deleteFrom. An insert takes the rows of the table's insert type (what the database fills may be left out; an unknown key or a value of another type does not compile), with onConflictDoNothing and onConflictDoUpdate; an update takes a partial row whose values are values or expressions; neither an update nor a delete can be run until it says where(...) or all(), so that a missing condition is not a table emptied. returning gives the rows it changed, typed as a select's.
Source: commons/data/sql/typed/mutate.ts
4 of 9 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.
Deleteclassno test imports itclass Delete<R, I, N extends string, Row = never> extends Returning<R, I, N, Row>
A delete that can be written and run.
| Member | Type | What it is |
|---|
condition | Node | undefined | |
returning | <P extends Projection>(f: (c: Columns<R>) => P) => Delete<R, I, N, RowOfProjection<P>> & Statement<RowOfProjection<P>> | |
toSql | (d: Dialect) => Result<string, TypedError> | |
run | (on: Runner) => Promise<readonly Row[]> | |
write | (d: Dialect) => string | |
table | Table<R, I, N> | |
projection | readonly (readonly [string, Node])[] | undefined | |
tail | (c: Ctx) => string | |
project | <P extends Projection>(f: (c: Columns<R>) => P) => readonly (readonly [string, Node])[] | |
rowType? | Row | |
const deleteFrom: <R, I, N extends string>(table: Table<R, I, N>) => PendingDelete<R, I, N>
DELETE FROM.
Imported by 14 tests of the run (14 passed, 0 failed): the library's results
const excluded: <T>(column: Column<T>) => Expr<T>
The value that an insert proposed for a column, in onConflictDoUpdate (excluded).
Imported by 7 tests of the run (7 passed, 0 failed): the library's results
Insertclassno test imports itclass Insert<R, I, N extends string, Row = never> extends Returning<R, I, N, Row>
An insert.
| Member | Type | What it is |
|---|
query | { readonly keys: readonly string[]; readonly ast: SelectAst; } | undefined | Where the rows come from, where they are those of a select. |
rows | readonly I[] | |
conflict | { readonly target: readonly string[]; readonly set?: Readonly<Record<string, unknown>> | undefined; } | undefined | |
onConflictDoNothing | (...keys: readonly (keyof R & string)[]) => Insert<R, I, N, Row> | Where a row's key is already there, leave it. With the keys of a unique constraint or key; none is any. |
onConflictDoUpdate | (keys: readonly [keyof R & string, ...(keyof R & string)[]], set: { readonly [K in keyof R & string]?: Expr<R[K]> | R[K] | undefined; }) => Insert<R, I, N, Row> | Where a row's key is already there, change the row: each key of set to a value or an expression of the table's columns. |
returning | <P extends Projection>(f: (c: Columns<R>) => P) => Insert<R, I, N, RowOfProjection<P>> & Statement<RowOfProjection<P>> | What to give back of each row inserted. |
toSql | (d: Dialect) => Result<string, TypedError> | |
run | (on: Runner) => Promise<readonly Row[]> | |
write | (d: Dialect) => string | |
table | Table<R, I, N> | |
projection | readonly (readonly [string, Node])[] | undefined | |
tail | (c: Ctx) => string | |
project | <P extends Projection>(f: (c: Columns<R>) => P) => readonly (readonly [string, Node])[] | |
rowType? | Row | |
const insertInto: <R, I, N extends string>(table: Table<R, I, N>) => { select: <K extends keyof R & string>(keys: readonly [K, ...K[]], query: Select<Scope, { readonly [P in K]: R[P]; }>) => Insert<R, I, N, never>; values: (rows: I | readonly [I, ...I[]]) => Insert<R, I, N, never>; }
INSERT INTO: at least one row, of the table's insert type.
Imported by 43 tests of the run (43 passed, 0 failed): the library's results
PendingDeleteclassno test imports itclass PendingDelete<R, I, N extends string>
A delete that has not yet its condition.
| Member | Type | What it is |
|---|
table | Table<R, I, N> | |
where | (condition: (c: Columns<R>) => Expr<boolean>) => Delete<R, I, N, never> | The rows to delete. |
all | () => Delete<R, I, N, never> | Every row of the table: said on purpose. |
PendingUpdateclassno test imports itclass PendingUpdate<R, I, N extends string>
An update that has its values and not yet its condition.
| Member | Type | What it is |
|---|
table | Table<R, I, N> | |
values | Readonly<Record<string, unknown>> | |
where | (condition: (c: Columns<R>) => Expr<boolean>) => Update<R, I, N, never> | The rows to change. |
all | () => Update<R, I, N, never> | Every row of the table: said on purpose. |
Updateclassno test imports itclass Update<R, I, N extends string, Row = never> extends Returning<R, I, N, Row>
An update that can be written and run.
| Member | Type | What it is |
|---|
values | Readonly<Record<string, unknown>> | |
condition | Node | undefined | |
returning | <P extends Projection>(f: (c: Columns<R>) => P) => Update<R, I, N, RowOfProjection<P>> & Statement<RowOfProjection<P>> | |
toSql | (d: Dialect) => Result<string, TypedError> | |
run | (on: Runner) => Promise<readonly Row[]> | |
write | (d: Dialect) => string | |
table | Table<R, I, N> | |
projection | readonly (readonly [string, Node])[] | undefined | |
tail | (c: Ctx) => string | |
project | <P extends Projection>(f: (c: Columns<R>) => P) => readonly (readonly [string, Node])[] | |
rowType? | Row | |
const update: <R, I, N extends string>(table: Table<R, I, N>) => { set: (values: { readonly [K in keyof R & string]?: Expr<R[K]> | R[K] | undefined; } | ((c: Columns<R>) => { readonly [K in keyof R & string]?: Expr<R[K]> | R[K] | undefined; })) => PendingUpdate<R, I, N>; }
UPDATE: the values of the columns to change, which are values or expressions of the table's columns.
Imported by 7 tests of the run (7 passed, 0 failed): the library's results