IF Commons GitHub

sql/logical/schema

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0006-logical FR-010, 0006-logical FR-001, 0006-logical FR-002

The logical schema (commons data 0006-logical FR-001, FR-002, FR-010): a relational schema as plain data, in terms of tables, columns, keys, constraints and indexes and of no engine. Every element has an identity of its own, made of its words, and carries from, the identity of the governance element it was made from, so that it is traced back. Names are lists of words (0005-naming): the physical schema writes them in a case style.

Source: commons/data/sql/logical/schema.ts

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

carriedOffunction
function carriedOf<T>(element: { readonly governance: readonly Annotation[]; }, kind: AnnotationKind<T>): readonly T[]

The values of the annotations of a kind that an element of the schema carries, typed: a table, a column, a value set or the schema.

ParameterWhat it is
elementwhat carries them
kindthe kind of annotation

Returns: the values, in the order governance gave them

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

Checkinterfaceno test imports it
interface Check

A check: a named rule every row must satisfy.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
expressionCheckExpression
CheckExpressiontypeno test imports it
type CheckExpression =
  | { readonly kind: "differs"; readonly columns: readonly [Words, Words] }
  | { readonly kind: "oneOf"; readonly column: Words; readonly codes: readonly string[] }
  | { readonly kind: "range"; readonly column: Words; readonly min?: number; readonly max?: number }
  | { readonly kind: "pattern"; readonly column: Words; readonly pattern: string };

What a check says. A code is by its name: the physical schema writes its stored value (0005-naming FR-006).

CodeRowinterfaceno test imports it
interface CodeRow

A row of a code table: the code by its name, its label and what it means.

MemberTypeWhat it is
codestring
labelstring
descriptionstring | null
Columninterfaceno test imports it
interface Column

A column.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
typeLogicalType
nullableboolean
default?LogicalDefault
commentstringWhat governance said it is: the definition of what it was made from.
governancereadonly Annotation[]The annotations of governance that this column carries for the layers below.
roleColumnRole
ColumnRoletypeno test imports it
type ColumnRole = "attribute" | "reference" | "audit" | "code";

Where a column came from.

columnIdconstno test imports it
const columnId: (table: Words, column: Words) => LogicalId

The identity of a column of a table.

ConstraintKindtypeno test imports it
type ConstraintKind = "pk" | "fk" | "uq" | "ck" | "ix";

The kinds of constraint and index.

constraintIdconstno test imports it
const constraintId: (kind: ConstraintKind, name: Words) => LogicalId

The identity of a constraint or an index.

ForeignKeyinterfaceno test imports it
interface ForeignKey

A foreign key: columns of a table that refer to columns of another.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
columnsreadonly Words[]
references{ readonly table: Words; readonly columns: readonly Words[]; }
Indexinterfaceno test imports it
interface Index

An index: how rows are found by columns, in order.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
columnsreadonly Words[]
LogicalDefaulttypeno test imports it
type LogicalDefault =
  | { readonly kind: "literal"; readonly value: string | number | boolean }
  | { readonly kind: "now" }
  | { readonly kind: "code"; readonly name: string };

What a column takes where no value is given: a literal, the moment of the insert, or a code of a list (by its name).

LogicalIdtypeno test imports it
type LogicalId = Brand<string, "LogicalId">;

The identity of an element of a logical schema, made of its words.

LogicalSchemainterface
interface LogicalSchema

The logical schema of a domain.

MemberTypeWhat it is
idLogicalId
fromElementId
domainstring
commentstring
tablesreadonly Table[]
valueSetsreadonly ValueSet[]The closed code lists, which no table holds.
governancereadonly Annotation[]The annotations of the domain, which the schema carries.

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

LogicalTypetypeno test imports it
type LogicalType = | { readonly kind: "text"; readonly max?: number } | { readonly kind: "integer" } | { readonly … (436 characters)
type LogicalType =
  | { readonly kind: "text"; readonly max?: number }
  | { readonly kind: "integer" }
  | { readonly kind: "decimal"; readonly precision?: number; readonly scale?: number }
  | { readonly kind: "boolean" }
  | { readonly kind: "date" }
  | { readonly kind: "timestamp"; readonly zone: boolean }
  | { readonly kind: "json" }
  | { readonly kind: "bytes" }
  | { readonly kind: "vector"; readonly dimensions: number };

The logical types: none is an engine's.

sameWordsconstno test imports it
const sameWords: (a: Words, b: Words) => boolean

Whether two lists of words are the same.

columnNamedfunctionno test imports it
function columnNamed(table: Table, name: string): Column | undefined

The column of a table that governance names (partyId, givenName).

ParameterWhat it is
tablethe table
namethe name as governance writes it, lower camel case

Returns: the column, or none

featureIdconstno test imports it
const featureId: (kind: FeatureKind, name: Words) => LogicalId

The identity of what a feature of an extension makes, by its kind and name.

FeatureKindtypeno test imports it
type FeatureKind = "view" | "routine" | "policy" | "partition" | "grant" | "object";

What a feature of an extension makes: the identity of a thing the schema does not have (0009-sql-features).

tableNamedfunctionno test imports it
function tableNamed(schema: LogicalSchema, name: string): Table | undefined

The table of a schema that governance names (party, partyIdentifier).

ParameterWhat it is
schemathe logical schema
namethe name as governance writes it, lower camel case

Returns: the table, or none

schemaIdconstno test imports it
const schemaId: (domain: string) => LogicalId

The identity of the schema of a domain.

Tableinterfaceno test imports it
interface Table

A table.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
commentstring
roleTableRole
columnsreadonly Column[]
primaryKeyreadonly Words[]
foreignKeysreadonly ForeignKey[]
uniquesreadonly Unique[]
checksreadonly Check[]
indexesreadonly Index[]
rows?readonly CodeRow[]The rows of a code table.
governancereadonly Annotation[]The annotations of governance that this table carries for the layers below.
tableIdconstno test imports it
const tableId: (table: Words) => LogicalId

The identity of a table.

TableRoletypeno test imports it
type TableRole = "concept" | "code" | "junction" | "values";

Why a table exists.

Uniqueinterfaceno test imports it
interface Unique

Columns that are unique together.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
columnsreadonly Words[]
ValueSetinterfaceno test imports it
interface ValueSet

A value set: a closed code list, which has no table, kept with its codes and what governance said of it.

MemberTypeWhat it is
idLogicalId
fromElementId
nameWords
commentstring
codesreadonly CodeRow[]
governancereadonly Annotation[]
valueSetIdconstno test imports it
const valueSetId: (name: Words) => LogicalId

The identity of a value set: a closed code list.

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