Columnstypeno test imports ittype Columns<R> = { readonly [K in keyof R & string]: Column<R[K]> };The columns of a row type, each an expression that gives its value.
Typed tables (commons data 0053-sql-typed): a table is a value with the types of its rows (R, what a select gives), of what an insert takes (I, where what the database fills may be left out) and the name by which it is known in a query (N), and with a typed column for each of its keys. The keys are the names a program writes (camel case); the names in SQL are written as the table says. A table is made by hand with defineTable or by the generator of this unit from a model, with the types a model says.
Columnstypeno test imports ittype Columns<R> = { readonly [K in keyof R & string]: Column<R[K]> };The columns of a row type, each an expression that gives its value.
defineTableconstconst defineTable: <R, I, N extends string>(spec: TableSpec<R, N>) => Table<R, I, N>Makes a table.
interface Author { id: number; name: string; bio: string | null }
interface AuthorInsert { id?: number; name: string; bio?: string | null }
const author = defineTable<Author, AuthorInsert, "author">({ alias: "author", name: "author", columns: { id: "id", name: "name", bio: "bio" }, primaryKey: ["id"] });ForeignKeyInfointerfaceno test imports itinterface ForeignKeyInfoA foreign key as the model says it, by the keys of the columns.
| Member | Type | What it is |
|---|---|---|
columns | readonly string[] | |
references | string | |
referencesColumns | readonly string[] |
NullableColumnstypeno test imports ittype NullableColumns<R> = { readonly [K in keyof R & string]: Column<R[K] | null> };The same where the table may be missing from a row (the other side of an outer join): every column may be null.
TableSpecinterfaceno test imports itinterface TableSpec<R, N extends string>What defineTable is told.
| Member | Type | What it is |
|---|---|---|
alias | N | The name in a query, which keys the scope of a select. |
name | string | The name in SQL. |
schema? | string | |
columns | { readonly [K in keyof R & string]: string; } | key → name in SQL, for each key of the row. |
primaryKey? | readonly (keyof R & string)[] | |
foreignKeys? | readonly ForeignKeyInfo[] |