IF Commons GitHub

sql/lifecycle/state

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0011-sql-lifecycle FR-004, 0011-sql-lifecycle FR-002

The state of a database (commons data 0011-sql-lifecycle FR-002): the written structure of its tables as a plain value, made from a logical schema bound to a dialect and a naming. It is addressed by its hash, so two states of the same structure are one state whatever order their tables were made in, and a state of another dialect or another naming is another state. What a person said of the past (renamedFrom) is a hint carried beside the structure and is not part of it.

Source: commons/data/sql/lifecycle/state.ts

7 of 10 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

canonicalStatefunction
function canonicalState(state: State): unknown

A state in the order that makes its hash: tables and columns by their words, constraints by what they are, identities and hints left out.

Imported by 7 tests of the run (7 passed, 0 failed): the library's results

emptyStateconst
const emptyState: (dialect: string, naming: { readonly names: string; readonly codes: string; }, qualifier?: string | undefined) => State

A state with no table, which an empty database is in.

ParameterWhat it is
dialectthe dialect's name
namingthe names of the case styles
qualifierthe schema, where the dialect has schemas and one was given

Returns: the empty state

Imported by 75 tests of the run (75 passed, 0 failed): the library's results

Stateinterface
interface State

The state of a database.

MemberTypeWhat it is
format1
dialectstring
naming{ readonly names: string; readonly codes: string; }
qualifier?stringThe schema the tables are qualified by, where the dialect has schemas and one was given (0013-sql-qualified-names FR-006).
tablesreadonly StateTable[]

Imported by 71 tests of the run (71 passed, 0 failed): the library's results

StateColumninterface
interface StateColumn

A column as written.

MemberTypeWhat it is
idstring
wordsreadonly string[]The words of its name, which are what it is, whatever case style writes them.
namestring
typestring
nullableboolean
default?string
renamedFrom?readonly string[]The words the column had, where governance says it was renamed. A hint: it is not part of the structure.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

StateConstraintinterfaceno test imports it
interface StateConstraint

A foreign key, a unique, a check or an index as written; signature is what it is, apart from its name.

MemberTypeWhat it is
idstring
kind"check" | "foreignKey" | "index" | "unique"
namestring
signaturestring
textstringThe clause that makes it, as CREATE TABLE or ADD writes it.
StateOptionsinterfaceno test imports it
interface StateOptions

What a state is made with.

MemberTypeWhat it is
dialectDialect
naming?Naming
schema?stringThe schema the tables are in.
tableClauses?readonly TableClause[]What extensions add to the end of a table; the lifecycle diffs them as part of the table.
StateRowinterfaceno test imports it
interface StateRow

A row of a code table as written.

MemberTypeWhat it is
codestring
labelstring
descriptionstring | null
StateTableinterface
interface StateTable

A table as written.

MemberTypeWhat it is
idstring
wordsreadonly string[]
namestring
columnsreadonly StateColumn[]
primaryKeyreadonly string[]The written names of the primary key's columns, in order.
constraintsreadonly StateConstraint[]
rowsreadonly StateRow[]
clause?stringWhat an extension adds to the end of CREATE TABLE (a partition), as written.
renamedFrom?readonly string[]The words the table had, where governance says it was renamed. A hint: it is not part of the structure.

Imported by 29 tests of the run (29 passed, 0 failed): the library's results

snapshotOffunction
function snapshotOf(schema: LogicalSchema, options: StateOptions): { readonly kind: "ok"; readonly value: State; } | { readonly kind: "err"; readonly error: readonly PhysicalError[]; }

The state a logical schema leaves a database in.

ParameterWhat it is
schemathe logical schema
optionsthe dialect, the naming and the table clauses

Returns: the state, or every error of writing it

Imported by 86 tests of the run (86 passed, 0 failed): the library's results

stateHashconst
const stateHash: (state: State) => string

The hash of a state: the SHA-256 of its canonical JSON.

ParameterWhat it is
statethe state

Returns: 64 hexadecimal digits

Imported by 78 tests of the run (78 passed, 0 failed): the library's results

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