IF Commons GitHub

sql/extensions/queries/catalog

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0024-sql-queries FR-001, 0024-sql-queries FR-002, 0024-sql-queries FR-003, 0024-sql-queries FR-006

A catalog of queries (commons data 0024-sql-queries): SQL a person writes over the names of a schema, with typed parameters that enter only as literals, read-only by construction, and compared between versions of a schema.

Source: commons/data/sql/extensions/queries/catalog.ts

4 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.

CatalogOptionsinterfaceno test imports it
interface CatalogOptions

What a catalog is made with.

MemberTypeWhat it is
dialectDialect
naming?Naming
schema?stringThe schema the tables are in, as bind was given it.
impactfunction
function impact(specs: readonly QuerySpec[], from: LogicalSchema, to: LogicalSchema, options: CatalogOptions): readonly Impact[]

What a change to a schema does to each query.

ParameterWhat it is
specsthe queries
fromthe schema before
tothe schema after
optionsthe dialect, naming and the tables' schema

Returns: for each query: fine in both, breaks (fine before, broken after), broken in both, or fixed (broken before, fine after)

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

Impactinterfaceno test imports it
interface Impact

What a change does to a query.

MemberTypeWhat it is
querystring
status"breaks" | "broken" | "fine" | "fixed"
errorsreadonly QueryError[]Why it is broken in the second version.
ParamErrortypeno test imports it
type ParamError =
  | { readonly kind: "missing"; readonly param: string }
  | { readonly kind: "unknown"; readonly param: string }
  | { readonly kind: "type"; readonly param: string; readonly expected: ParamType }
  | { readonly kind: "null"; readonly param: string };

Why a parameter of a catalogued query is refused, as a value.

ParamSpecinterfaceno test imports it
interface ParamSpec

A parameter: its type, and whether it may be null.

MemberTypeWhat it is
typeParamType
nullable?boolean
ParamTypetypeno test imports it
type ParamType = "text" | "integer" | "number" | "boolean";

The type of a parameter.

QueryErrortypeno test imports it
type QueryError =
  | RefError
  | { readonly kind: "duplicate"; readonly name: string }
  | { readonly kind: "not-read-only"; readonly query: string; readonly why: string }
  | { readonly kind: "unknown-param"; readonly query: string; readonly param: string };

Why a catalogued query cannot be found or run, as a value.

QuerySpecinterface
interface QuerySpec

What a project says of a query.

MemberTypeWhat it is
namestring
params?Readonly<Record<string, ParamSpec | ParamType>>
sql(refs: Refs, param: (name: string) => string) => stringThe SQL, given the references of the schema and a function that gives the place of a parameter.

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

queriesfunction
function queries(schema: LogicalSchema, specs: readonly QuerySpec[], options: CatalogOptions): Result<Catalog, readonly QueryError[]>

A catalog of queries.

ParameterWhat it is
schemathe logical schema
specsthe queries
optionsthe dialect, naming and the tables' schema

Returns: the catalog, or why not

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

readOnlyfunction
function readOnly(sql: string, dialect?: string): string | undefined

Why a query is not read-only, or nothing: the guard of the SQL language library reads it with the parser of the dialect (0024-sql-queries FR-003), so that a word of a write in a string, a quoted name or a comment is not a write, and the places of its parameters are read as NULL.

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

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