IF Commons GitHub

aide/catalog/mod

Catalog, names and types (commons lang-sql 0010-aide FR-003, FR-004): a Catalog says the tables and functions of a language; bind resolves the names of a query against it, with aliases and the scopes of subqueries, and typeOf and check give the type of an expression and each use that cannot be right. Everything is data and errors are values, with the span of the name and, for a name close to one that exists, the name that was meant.

Spec: 0010-aide FR-003, FR-004

Source: commons/lang-sql/src/aide/catalog/mod.ts

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

Typetypeno test imports it
type Type = "int" | "float" | "text" | "bool" | "timestamp" | "null" | "unknown";

The types of the values of a language.

TableSpecinterfaceno test imports it
interface TableSpec

A table: its columns and their types, in order.

MemberTypeWhat it is
columnsReadonly<Record<string, Type>>
FunctionSiginterfaceno test imports it
interface FunctionSig

A function: the types of its parameters (undefined where any), how many it needs at least, and the type it gives.

MemberTypeWhat it is
namestring
paramsreadonly Type[] | undefined
minArgsnumber
maxArgsnumber | undefined
resultType
Cataloginterface
interface Catalog

What a language's tables and functions are.

MemberTypeWhat it is
tablesReadonly<Record<string, TableSpec>>
functionsreadonly FunctionSig[]

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

BoundColumninterfaceno test imports it
interface BoundColumn

A column that a name was resolved to.

MemberTypeWhat it is
tablestring
aliasstring
columnstring
typeType
BindErrorinterfaceno test imports it
interface BindError

Something wrong with the names or types of a query.

MemberTypeWhat it is
startnumber
endnumber
messagestring
suggestion?stringThe name that was meant, where one is close.
Boundinterfaceno test imports it
interface Bound

A query with its names resolved.

MemberTypeWhat it is
selectSelect
catalogCatalog
columnsReadonlyMap<Name, BoundColumn>The column each name of an expression stands for.
tablesreadonly { readonly name: string; readonly alias: string; }[]The tables of the query's own FROM, with their aliases.
TableDescriptioninterfaceno test imports it
interface TableDescription

A table as another system says it: its columns' names and the types of that system.

MemberTypeWhat it is
namestring
columnsreadonly { readonly name: string; readonly type: string; }[]
catalogFromTablesfunction
function catalogFromTables(tables: readonly TableDescription[], types?: Readonly<Record<string, Type>>, functions?: readonly FunctionSig[]): Catalog

A catalog of tables described in the types of another system; types maps those types (without regard to case) to the types of a catalog, and a type that is in neither is unknown.

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

closestfunction
function closest(name: string, candidates: readonly string[]): string | undefined

The candidate closest to a name, where one is within two edits (the first in order where two are).

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

bindfunction
function bind(select: Select, catalog: Catalog): Result<Bound, readonly BindError[]>

Resolves the names of a query against a catalog; every unknown table, unknown column and ambiguous column is an error value.

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

typeOffunction
function typeOf(e: Expr, b: Bound): Type

The type of an expression of a bound query.

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

checkfunction
function check(b: Bound): readonly BindError[]

Every use in a bound query that cannot be right: a comparison of text with a number, arithmetic on text, a function with the wrong number or types of arguments.

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

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