IF Commons GitHub

sql/physical/statement

Written to: 5 requirements: 5 proved, 0 partly, 0 failing, 0 with no test recorded. 0007-physical FR-003, 0007-physical FR-006, 0007-physical FR-009, 0007-physical FR-010, 0007-physical FR-011

What bind makes and what an extension may add (commons data 0007-physical): a statement is a piece of SQL with its group and the logical elements it was made from, so that what is in a database is traced back; a physical schema is the statements in the order the groups say; and a source is what an extension is given to add statements for a bound schema, with the written name of every table and column.

Source: commons/data/sql/physical/statement.ts

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

BindContextinterface
interface BindContext

What a source is given.

MemberTypeWhat it is
schemaLogicalSchema
dialectDialect
namingNaming
writtenWritten
schemaName?stringThe schema the tables are in, as the project gave it.

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

GROUPSconst
const GROUPS: readonly Group[]

The groups in the order their statements are run.

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

Grouptypeno test imports it
type Group = "setup" | "table" | "constraint" | "index" | "data" | "view" | "routine" | "documentation" | "policy";

Where a statement goes: tables, then what is added to them, then indexes, then the reference data, then documentation, then policies.

Origintypeno test imports it
type Origin = "core" | "extension";

Whether a statement is the core's, made from the logical schema, or an extension's (0011-sql-lifecycle FR-003).

Physicalinterface
interface Physical

A bound schema: the statements, in the order of their groups.

MemberTypeWhat it is
dialectstring
naming{ readonly names: string; readonly codes: string; }
statementsreadonly Statement[]

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

PhysicalErrortype
type PhysicalError = | { readonly kind: "unsupported"; readonly element: LogicalId; readonly why: string } | { reado… (420 characters)
type PhysicalError =
  | { readonly kind: "unsupported"; readonly element: LogicalId; readonly why: string }
  | { readonly kind: "length"; readonly element: LogicalId; readonly name: string; readonly max: number }
  | { readonly kind: "collision"; readonly name: string; readonly table?: string; readonly first: LogicalId; readonly second: LogicalId }
  | { readonly kind: "cycle"; readonly tables: readonly string[] };

What is wrong with a binding; bind returns all of it together.

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

clausesFromfunctionno test imports it
function clausesFrom(composition: Composition): readonly TableClause[]

The table clauses of a composition, in its order.

ParameterWhat it is
compositionthe project's composition

Returns: the clauses its extensions contribute

renderfunction
function render(physical: Physical): string

The statements as the text of a script: a blank line between them, the same text every time.

ParameterWhat it is
physicalthe bound schema

Returns: the script

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

sourcesFromfunction
function sourcesFrom(composition: Composition): readonly StatementSource[]

The sources of a composition, in its order.

ParameterWhat it is
compositionthe project's composition

Returns: the sources its extensions contribute

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

TableClausetypeno test imports it
type TableClause = (context: BindContext, table: Table) => Result<string | undefined, readonly PhysicalError[]>;

What an extension gives bind to add to the end of a table's CREATE TABLE: a clause, nothing for a table it has none for, or its errors (0009-sql-features FR-004).

tableClausesPointconstno test imports it
const tableClausesPoint: ContributionPoint<TableClause>

The contribution point an extension fills to add a clause to a table.

Statementinterfaceno test imports it
interface Statement

One piece of SQL, ending in ;.

MemberTypeWhat it is
groupGroup
origin?OriginWho made it: bind sets it, so an extension never has to.
sqlstring
ofreadonly LogicalId[]The elements of the logical schema it was made from.
StatementSourcetype
type StatementSource = (context: BindContext) => Result<readonly Statement[], readonly PhysicalError[]>;

What an extension gives bind: statements for a bound schema, or its errors.

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

statementsPointconst
const statementsPoint: ContributionPoint<StatementSource>

The contribution point an extension fills to add statements.

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

Writteninterfaceno test imports it
interface Written

The names that were written, by the logical element they are the name of.

MemberTypeWhat it is
qualifierstring | undefinedThe schema tables are qualified by, where the dialect has schemas and one was given.
ref(id: LogicalId) => stringThe reference to a table of the schema, quoted and qualified (0013-sql-qualified-names FR-004).
qualify(name: string) => stringThe reference to a table of an extension, by the bare name it is written by: qualified, or with the schema's words added where the dialect has no schemas.
tableName(name: string) => stringThe name a table of an extension is written by once the schema's words are added where the dialect has no schemas.
table(id: LogicalId) => string | undefined
column(id: LogicalId) => string | undefined
constraint(id: LogicalId) => string | undefined

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