IF Commons GitHub

governance/values

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-sql-port FR-001

The port of a database: the least a store asks of a driver. A value is null, a number, a wide integer, a text or bytes; a row is its values by the name of the column; a runner runs one statement of text with parameters; a port is a runner that also keeps a transaction (all or none) and closes. It is a type of data and of functions, so that any driver, a client a caller already has, fits it by its shape.

import type { SqlPort } from "./values.ts";
declare const port: SqlPort;
await port.query("SELECT 1 AS one", []); // [{ one: 1 }]

Source: commons/anyfs-sql/src/governance/values.ts

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

SqlValuetypeno test imports it
type SqlValue = null | bigint | number | string | Uint8Array;

What a column holds, as a driver gives it and takes it.

SqlRowtypeno test imports it
type SqlRow = Readonly<Record<string, SqlValue>>;

A row: its values by the name of the column.

SqlRunnertypeno test imports it
type SqlRunner = {
  /** Runs a statement and gives the rows it returns (none for one that returns none). */
  query(sql: string, params: readonly SqlValue[]): Promise<readonly SqlRow[]>;
  /** Runs a statement, or several with no parameters, and gives nothing. */
  exec(sql: string, params: readonly SqlValue[]): Promise<void>;
};

Runs one statement. A statement is text with parameters written as the dialect writes them, in the order they appear.

SqlPorttype
type SqlPort = SqlRunner & { readonly dialect: SqlDialect; /** Runs the function in a transaction that holds until i… (604 characters)
type SqlPort = SqlRunner & {
  readonly dialect: SqlDialect;
  /** Runs the function in a transaction that holds until it returns and is undone where it throws; no other statement of this port runs in between, where the driver has one connection. */
  transaction<T>(run: (tx: SqlRunner) => Promise<T>): Promise<T>;
  /** Brings what the engine holds in a log back into the file, so that the file alone is the whole database: a file copied after it is complete. Only a port of an engine that keeps a log has it (SQLite in write-ahead mode). */
  checkpoint?(): Promise<void>;
  close(): Promise<void>;
};

A database: the dialect it speaks, a runner for one statement, and a transaction.

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

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