IF Commons GitHub

sql/typed/mutate

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 it
class Delete<R, I, N extends string, Row = never> extends Returning<R, I, N, Row>

A delete that can be written and run.

MemberTypeWhat it is
conditionNode | 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
tableTable<R, I, N>
projectionreadonly (readonly [string, Node])[] | undefined
tail(c: Ctx) => string
project<P extends Projection>(f: (c: Columns<R>) => P) => readonly (readonly [string, Node])[]
rowType?Row
deleteFromconst
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

excludedconst
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 it
class Insert<R, I, N extends string, Row = never> extends Returning<R, I, N, Row>

An insert.

MemberTypeWhat it is
query{ readonly keys: readonly string[]; readonly ast: SelectAst; } | undefinedWhere the rows come from, where they are those of a select.
rowsreadonly 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
tableTable<R, I, N>
projectionreadonly (readonly [string, Node])[] | undefined
tail(c: Ctx) => string
project<P extends Projection>(f: (c: Columns<R>) => P) => readonly (readonly [string, Node])[]
rowType?Row
insertIntoconst
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 it
class PendingDelete<R, I, N extends string>

A delete that has not yet its condition.

MemberTypeWhat it is
tableTable<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 it
class PendingUpdate<R, I, N extends string>

An update that has its values and not yet its condition.

MemberTypeWhat it is
tableTable<R, I, N>
valuesReadonly<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 it
class Update<R, I, N extends string, Row = never> extends Returning<R, I, N, Row>

An update that can be written and run.

MemberTypeWhat it is
valuesReadonly<Record<string, unknown>>
conditionNode | 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
tableTable<R, I, N>
projectionreadonly (readonly [string, Node])[] | undefined
tail(c: Ctx) => string
project<P extends Projection>(f: (c: Columns<R>) => P) => readonly (readonly [string, Node])[]
rowType?Row
updateconst
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

Titles, headings, exports, tables, columns and requirements. Esc closes.