IF Commons GitHub

sql/typed/expr

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0053-sql-typed FR-001, 0053-sql-typed FR-002

Typed expressions (commons data 0053-sql-typed): a value of SQL is an Expr<T>, where T is the TypeScript type of what it gives, nullable where it may be null. The operators take expressions of one type and give expressions, so that a comparison of a number with a text, or a sum of a name, does not compile. An expression is data (a tree); compile.ts writes it for a dialect.

Source: commons/data/sql/typed/expr.ts

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

addconst
const add: <T extends number | null>(a: Expr<T>, b: Operand<number>) => Expr<T>

a + b, of numbers.

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

andconst
const and: (...parts: readonly Expr<boolean>[]) => Expr<boolean>

Every condition holds; with none it is true.

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

ascconst
const asc: (e: Expr<unknown>) => Order

Ascending.

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

avgconstno test imports it
const avg: (a: Expr<number | null>) => Expr<number | null>

avg(a): null where there is no row.

betweenconst
const between: <T>(a: Expr<T>, low: Operand<NonNullable<T>>, high: Operand<NonNullable<T>>) => Expr<boolean>

a BETWEEN low AND high.

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

chooseconst
const choose: <T>(whens: readonly (readonly [Expr<boolean>, Operand<T>])[], otherwise: Operand<T>) => Expr<T>

CASE WHEN ... THEN ... ELSE ... END.

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

coalesceconst
const coalesce: <T>(a: Expr<T>, fallback: Operand<NonNullable<T>>) => Expr<NonNullable<T>>

The first that is not null; the last is a value that is, so the result is not null.

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

concatconstno test imports it
const concat: <T extends string | null>(a: Expr<T>, b: Operand<string>) => Expr<T>

The texts joined (||).

countconst
const count: () => Expr<number>

count(*).

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

countDistinctconstno test imports it
const countDistinct: (a: Expr<unknown>) => Expr<number>

count(DISTINCT a).

countOfconst
const countOf: (a: Expr<unknown>) => Expr<number>

count(a): the rows where it is not null.

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

descconst
const desc: (e: Expr<unknown>) => Order

Descending.

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

eqconst
const eq: <T>(a: Expr<T>, b: Operand<NonNullable<T>>) => Expr<boolean>

a = b; a null is never equal (use isNull).

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

gtconst
const gt: <T>(a: Expr<T>, b: Operand<NonNullable<T>>) => Expr<boolean>

a > b.

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

gteconstno test imports it
const gte: <T>(a: Expr<T>, b: Operand<NonNullable<T>>) => Expr<boolean>

a >= b.

ilikeconst
const ilike: (a: Expr<string | null>, pattern: Operand<string>) => Expr<boolean>

A case-blind LIKE, written the same on every dialect (lower(a) LIKE lower(pattern)).

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

inListconst
const inList: <T>(a: Expr<T>, values: readonly Operand<NonNullable<T>>[]) => Expr<boolean>

a IN (...); an empty list is false.

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

isNotNullconst
const isNotNull: (a: Expr<unknown>) => Expr<boolean>

a IS NOT NULL.

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

isNullconst
const isNull: (a: Expr<unknown>) => Expr<boolean>

a IS NULL.

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

likeconst
const like: (a: Expr<string | null>, pattern: Operand<string>) => Expr<boolean>

a LIKE pattern.

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

litconst
const lit: <T extends string | number | boolean | Date | null | readonly number[] | object>(value: T) => Expr<T>

A value as an expression.

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

lowerconst
const lower: <T extends string | null>(a: Expr<T>) => Expr<T>

lower(a).

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

ltconstno test imports it
const lt: <T>(a: Expr<T>, b: Operand<NonNullable<T>>) => Expr<boolean>

a < b.

lteconst
const lte: <T>(a: Expr<T>, b: Operand<NonNullable<T>>) => Expr<boolean>

a <= b.

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

maxconst
const max: <T>(a: Expr<T>) => Expr<T | null>

max(a): null where there is no row.

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

minconstno test imports it
const min: <T>(a: Expr<T>) => Expr<T | null>

min(a): null where there is no row.

mulconstno test imports it
const mul: <T extends number | null>(a: Expr<T>, b: Operand<number>) => Expr<T>

a * b, of numbers.

neconst
const ne: <T>(a: Expr<T>, b: Operand<NonNullable<T>>) => Expr<boolean>

a <> b.

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

notconst
const not: (a: Expr<boolean>) => Expr<boolean>

NOT a.

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

notInListconstno test imports it
const notInList: <T>(a: Expr<T>, values: readonly Operand<NonNullable<T>>[]) => Expr<boolean>

a NOT IN (...); an empty list is true.

Operandtypeno test imports it
type Operand<T> = Expr<T> | T;

What an operator takes where an expression of type T is wanted: the expression, or a plain value of the type.

orconst
const or: (...parts: readonly Expr<boolean>[]) => Expr<boolean>

Some condition holds; with none it is false.

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

Orderinterfaceno test imports it
interface Order

One term of an ORDER BY.

MemberTypeWhat it is
eExpr<unknown>
dir"ASC" | "DESC"
subconstno test imports it
const sub: <T extends number | null>(a: Expr<T>, b: Operand<number>) => Expr<T>

a - b, of numbers.

sumconst
const sum: (a: Expr<number | null>) => Expr<number | null>

sum(a): null where there is no row.

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

upperconstno test imports it
const upper: <T extends string | null>(a: Expr<T>) => Expr<T>

upper(a).

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