type
Engine
export type Engine = "postgresql" | "mysql" | "sqlite";Which SQL dialect a [Queryable] speaks, which decides placeholder syntax.
Readiness: Implemented
API reference
The runtime for sqlc's Flow target: exact codecs and driver adapters, part of the Unified Toolchain for Flow.
Written from the source by uf doc when this site was built: the signature and the comment above each export, grouped by the specifier a program imports it from.
@uniflowed/sqltype
Engineexport type Engine = "postgresql" | "mysql" | "sqlite";Which SQL dialect a [Queryable] speaks, which decides placeholder syntax.
type
SqlParamexport type SqlParam = null | string | number | bigint | Uint8Array;A parameter as it goes to an adapter.
Already encoded by a codec: PostgreSQL and MySQL parameters are text (or bytes) and the server casts them to the type the statement needs, which is the one representation every driver sends unchanged. SQLite parameters are its storage classes.
type
Rowexport type Row = $ReadOnlyArray<mixed>;One row, positionally: a join may return two columns called id.
type
QueryResultexport type QueryResult = {|
readonly rows: $ReadOnlyArray<Row>,
/** Rows inserted, updated or deleted; 0 for a statement that changes none. */
readonly rowsAffected: number,
/** MySQL's `LAST_INSERT_ID()` and SQLite's `last_insert_rowid()`; `null` on PostgreSQL. */
readonly lastInsertId: bigint | null,
|};What a statement produced.
type
QueryModeexport type QueryMode = "rows" | "exec";Whether a statement is run for its rows or for its effect.
SQLite drivers have two entry points (all and run) and only the second reports changes and the last row id; the other engines ignore this.
type
Queryableexport type Queryable = {
readonly engine: Engine,
/** The most bound parameters one statement may carry; `:copyfrom` chunks under it. */
readonly maxParams: number,
query(text: string, params: $ReadOnlyArray<SqlParam>, mode: QueryMode): Promise<QueryResult>,
readonly transaction?: <T>(body: (tx: Queryable) => Promise<T>) => Promise<T>,
...
};A connection, a pool or an open transaction: anything generated code can run a statement on.
transaction is absent where the platform has no interactive transactions (Cloudflare D1). Inside a transaction it opens a savepoint.
type
JsonValueexport type JsonValue =
| null
| boolean
| number
| string
| $ReadOnlyArray<JsonValue>
| { readonly [string]: JsonValue };A JSON document, as json and jsonb columns decode to.
type
SqlFailureexport type SqlFailure =
| {| readonly kind: "decode", readonly expected: string, readonly value: mixed |}
| {| readonly kind: "encode", readonly expected: string, readonly value: mixed |}
| {| readonly kind: "shape", readonly expected: number, readonly actual: number |}
| {| readonly kind: "closed" |}
| {| readonly kind: "unsupported", readonly feature: string |};What went wrong, as a value.
class
SqlErrorexport class SqlError extends Error { ... }A value that did not fit its column, a row of the wrong width, or a transaction used after it ended.
Never a database error: those are the driver's, and are rethrown untouched so that a caller matching on code: "23505" still can.
function
decodeErrorexport function decodeError(expected: string, value: mixed): empty { ... }Throw a decode failure. For codecs.
function
encodeErrorexport function encodeError(expected: string, value: mixed): empty { ... }Throw an encode failure. For codecs.
function
oneexport function one<T>(
db: Queryable,
name: string,
text: string,
params: $ReadOnlyArray<SqlParam>,
width: number,
decode: (row: Row) => T,
): Promise<T | null> { ... }:one — the first row, or null.
function
manyexport function many<T>(
db: Queryable,
name: string,
text: string,
params: $ReadOnlyArray<SqlParam>,
width: number,
decode: (row: Row) => T,
): Promise<Array<T>> { ... }:many — every row.
function
execexport function exec(
db: Queryable,
name: string,
text: string,
params: $ReadOnlyArray<SqlParam>,
): Promise<void> { ... }:exec.
function
execRowsexport function execRows(
db: Queryable,
name: string,
text: string,
params: $ReadOnlyArray<SqlParam>,
): Promise<number> { ... }:execrows — how many rows the statement changed.
type
ExecResultexport type ExecResult = {|
readonly rowsAffected: number,
readonly lastInsertId: bigint | null,
|};What :execresult resolves to.
function
execResultexport function execResult(
db: Queryable,
name: string,
text: string,
params: $ReadOnlyArray<SqlParam>,
): Promise<ExecResult> { ... }:execresult — the affected-row count and, on MySQL and SQLite, the last id.
function
execLastIdexport function execLastId(
db: Queryable,
name: string,
text: string,
params: $ReadOnlyArray<SqlParam>,
): Promise<bigint> { ... }:execlastid — the id the statement inserted.
PostgreSQL has no such thing; sqlc's answer there is RETURNING id with :one, and this throws rather than resolve to a made-up zero.
class
Sliceexport class Slice { ... }A sqlc.slice argument, already encoded element by element.
function
sliceexport function slice(values: $ReadOnlyArray<SqlParam>): Slice { ... }Wrap an encoded list as one sqlc.slice argument.
function
expandexport function expand(
parts: $ReadOnlyArray<string>,
values: $ReadOnlyArray<SqlParam | Slice>,
): {| readonly text: string, readonly params: $ReadOnlyArray<SqlParam> |} { ... }Join parts around the slices in values, in order.
values are the statement's parameters in placeholder order; each [Slice] sits where a marker was, between parts[k] and parts[k + 1]. A non-empty slice becomes ?, ?, …; an empty one becomes NULL, so x IN (NULL) is false for every row — sqlc's own semantics, and what a list of nothing should match.
type
CopyPlanexport type CopyPlan = {|
readonly head: string,
readonly tuple: $ReadOnlyArray<string>,
readonly refs: $ReadOnlyArray<number>,
readonly tail: string,
|};An INSERT … VALUES (…) statement split so it can be repeated per row.
tuple is the parenthesised group around its placeholders and refs says which field of a row each placeholder takes, so (owner_id, name) with VALUES ($1, $2) is tuple: ["(", ", ", ")"], refs: [0, 1].
function
copyFromexport function copyFrom(
db: Queryable,
name: string,
plan: CopyPlan,
rows: $ReadOnlyArray<$ReadOnlyArray<SqlParam>>,
): Promise<number> { ... }:copyfrom — insert every row, as few statements as maxParams allows.
Inside one transaction when the Queryable can open one, so a failure in the third chunk does not leave the first two behind: pgx's CopyFrom is one COPY, and a caller of the generated function should not have to know it is now several statements. Resolves to the number of rows inserted.
function
batchexport function batch<A, R>(
db: Queryable,
items: $ReadOnlyArray<A>,
body: (q: Queryable, item: A) => Promise<R>,
): Promise<Array<R>> { ... }Run body once per item, in order, inside one transaction when there is one to open.
pgx sends a batch as one implicit transaction; this keeps the atomicity and the order without pgx. Where transaction is absent (D1) the items run in order without one, and the docs say so.
type
Runexport type Run = (
text: string,
params: $ReadOnlyArray<SqlParam>,
mode: QueryMode,
) => Promise<QueryResult>;How an adapter runs one statement on one connection.
type
Connectionexport type Connection = {|
readonly engine: Engine,
readonly maxParams: number,
readonly run: Run,
/** The statement that opens a transaction; `BEGIN` unless the adapter knows better. */
readonly begin?: string,
|};What [transactionOn] needs from an adapter.
function
transactionOnexport function transactionOn<T>(
connection: Connection,
body: (tx: Queryable) => Promise<T>,
): Promise<T> { ... }Run body in a transaction on connection, which must be a single connection nobody else is using until this settles.
Commits when body resolves and rolls back when it throws, rethrowing what it threw. The [Queryable] body receives stops working once this settles — a statement run on it afterwards would otherwise land outside the transaction without anyone noticing. Its own transaction opens a savepoint.
function
singleConnectionexport function singleConnection(connection: Connection): Queryable { ... }A [Queryable] over one connection that serves a whole application: a SQLite database, or an embedded PostgreSQL.
While a transaction is open every statement run on the returned value waits for it to finish, so a request that is not in the transaction never lands inside it. Statements run on the transaction's own [Queryable] do not wait.
@uniflowed/sql/postgresqltype
ArrayNodeexport type ArrayNode = string | null | $ReadOnlyArray<ArrayNode>;A node of a parsed array literal: an element's text, NULL, or a sub-array.
type
Codecexport type Codec<T> = {|
/** For messages: `int8`, `text[]`. */
readonly sqlType: string,
readonly decode: (value: mixed) => T,
readonly encode: (value: T) => string,
readonly element: (node: ArrayNode) => T,
/** The value as it appears inside `{…}`: quoted, or a nested literal. */
readonly literal: (value: T) => string,
/** How many array dimensions this codec reads; 0 for a scalar. */
readonly depth: number,
|};How one SQL type becomes a Flow value and back.
decode reads a column; encode writes a parameter. element and literal are the same two directions for a value inside an array literal, which is how [array] nests without re-parsing.
function
scalarexport function scalar<T>(
sqlType: string,
fromText: (text: string) => T,
toText: (value: T) => string,
): Codec<T> { ... }A scalar codec from its two text conversions.
variable
int2export const int2: Codec<number> = boundedInteger("int2");smallint, smallserial.
variable
int4export const int4: Codec<number> = boundedInteger("int4");integer, serial, oid and the other 32-bit integers.
variable
oidexport const oid: Codec<number> = scalar(
"oid",
(text) => integerFromText("oid", text),
(value) => {
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
return encodeError("oid (an integer from 0 to 4294967295)", value);
}
return String(value);
},
);oid, xid, cid and the reg* types: unsigned 32-bit.
variable
int8export const int8: Codec<bigint> = scalar(
"int8",
(text) => bigintFrom("int8", text),
(value) => {
if (typeof value !== "bigint") {
return encodeError("int8 (a bigint)", value);
}
return String(value);
},
);bigint, bigserial: every value, exactly.
variable
int8AsNumberexport const int8AsNumber: Codec<number> = scalar(
"int8",
(text) => integerFromText("int8", text),
(value) => {
if (!Number.isSafeInteger(value)) {
return encodeError("int8 (an integer within ±2^53)", value);
}
return String(value);
},
);bigint as a number, for a table that opted in with int8: "number"; throws past 2^53.
variable
int8AsStringexport const int8AsString: Codec<string> = scalar(
"int8",
(text) => text,
(value) => {
if (typeof value !== "string" || !DIGITS.test(value)) {
return encodeError("int8 (a string of digits)", value);
}
return value;
},
);bigint as its digits, for int8: "string".
variable
float4export const float4: Codec<number> = floatCodec("float4");real.
variable
float8export const float8: Codec<number> = floatCodec("float8");double precision.
variable
numericexport const numeric: Codec<string> = scalar(
"numeric",
(text) => text,
(value) => {
if (typeof value !== "string" || !NUMERIC.test(value)) {
return encodeError("numeric (a decimal string)", value);
}
return value;
},
);numeric/decimal as its exact decimal string.
variable
numericAsNumberexport const numericAsNumber: Codec<number> = floatCodec("numeric");numeric as a number, for numeric: "number". Rounds; that is what opting in means.
variable
moneyexport const money: Codec<string> = scalar(
"money",
(text) => text,
(value) => stringParam("money (a string)", value),
);money, in the server's lc_monetary format ($1,234.50), unchanged.
variable
boolexport const bool: Codec<boolean> = scalar(
"bool",
(text) => {
if (text === "t") {
return true;
}
if (text === "f") {
return false;
}
return decodeError("bool", text);
},
(value) => {
if (typeof value !== "boolean") {
return encodeError("bool (a boolean)", value);
}
return value ? "t" : "f";
},
);boolean.
function
textexport function text(sqlType: string): Codec<string> { ... }Any type whose text is the value: text, varchar, uuid, inet, interval, time, ranges, and types uf has no better representation for.
variable
stringexport const string: Codec<string> = text("text");text and the character types.
variable
byteaexport const bytea: Codec<Uint8Array> = scalar("bytea", bytesFromText, bytesToText);bytea.
variable
jsonexport const json: Codec<JsonValue> = scalar(
"json",
(value) => jsonFromText(value),
(value) => jsonParam(value),
);json and jsonb.
variable
dateexport const date: Codec<string> = text("date");date: YYYY-MM-DD, or infinity. A calendar date has no time zone, so it is not a Date.
variable
timestampexport const timestamp: Codec<string> = text("timestamp");timestamp without time zone: the wall-clock time as the server printed it.
variable
timestamptzAsStringexport const timestamptzAsString: Codec<string> = text("timestamptz");timestamptz as the server printed it, microseconds and all, for timestamptz: "string".
variable
timestamptzexport const timestamptz: Codec<Date> = scalar("timestamptz", instantFromText, instantToText);timestamp with time zone: an instant. Millisecond precision, which is a Date's.
variable
unknownexport const unknown: Codec<mixed> = {
sqlType: "unknown",
decode: (value) => value,
encode: (value) => {
if (typeof value === "string") {
return value;
}
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") {
return String(value);
}
if (value instanceof Date) {
return instantToText(value);
}
return jsonParam(value);
},
element: (node) => node,
literal: (value) => (value === null ? "NULL" : quote(String(value))),
depth: 0,
};A value sqlc could not type (any, anyelement, …): whatever the server printed.
function
enumerationexport function enumeration<T extends string>(
sqlType: string,
values: $ReadOnlyArray<T>,
): Codec<T> { ... }A codec for a CREATE TYPE … AS ENUM, from its labels in declaration order.
function
parseArrayexport function parseArray(literal: string): $ReadOnlyArray<ArrayNode> { ... }Parse an array literal: {1,2,NULL}, {{a,b},{c,d}}, {"a b","x\"y"}.
A literal with non-default bounds starts with a dimension decoration ([0:2]={…}); the bounds are not part of the value and are dropped.
function
arrayexport function array<T>(element: Codec<T>): Codec<$ReadOnlyArray<T>> { ... }An array of element. Nest it for more dimensions: array(array(int4)) is int4[][].
A NULL inside the array throws. sqlc does not tell a plugin whether a column's elements may be null, and typing them as T | null everywhere would make every text[] NOT NULL of tags awkward to use to guard against a case most schemas never produce; typing them T and returning null would be a lie. So the type is T, and the lie is refused at the boundary.
function
mapexport function map<T, U>(
codec: Codec<T>,
decode: (value: T) => U,
encode: (value: U) => T,
): Codec<U> { ... }An override's codec: decode narrows what codec read, encode widens a value back to what codec writes. Generated for overrides in the plugin options, where decode is the application's own check.
function
nullableexport function nullable<T>(codec: Codec<T>, value: mixed): T | null { ... }A NULLable value: the generated code's x === null ? null : codec.decode(x), for arrays of codecs that need it.
function
paramexport function param<T>(codec: Codec<T>, value: T | null): string | null { ... }Encode a nullable parameter.
@uniflowed/sql/mysqltype
MysqlParamexport type MysqlParam = null | string | Uint8Array;What a MySQL parameter is sent as.
type
Codecexport type Codec<T> = {|
readonly sqlType: string,
readonly decode: (value: mixed) => T,
readonly encode: (value: T) => MysqlParam,
|};How one MySQL type becomes a Flow value and back.
function
integerexport function integer(sqlType: string): Codec<number> { ... }TINYINT through INT, signed or unsigned, and YEAR: all fit a number.
variable
bigintexport const bigint: Codec<bigint> = {
sqlType: "bigint",
decode: (value) => bigintFrom("bigint", value),
encode: (value) => {
if (typeof value !== "bigint") {
return encodeError("bigint (a bigint)", value);
}
return String(value);
},
};BIGINT, signed or unsigned, exactly.
variable
bigintAsNumberexport const bigintAsNumber: Codec<number> = integer("bigint");BIGINT as a number, for int8: "number"; throws past 2^53.
variable
bigintAsStringexport const bigintAsString: Codec<string> = {
sqlType: "bigint",
decode: (value) => {
if (typeof value === "string" && /^[-+]?\d+$/.test(value)) {
return value;
}
return decodeError("bigint", value);
},
encode: (value) => stringParam("bigint (a string of digits)", value),
};BIGINT as its digits, for int8: "string".
variable
booleanexport const boolean: Codec<boolean> = {
sqlType: "tinyint(1)",
decode: (value) => {
if (value === "0" || value === 0) {
return false;
}
if (typeof value === "string" && /^-?\d+$/.test(value)) {
// MySQL's own truth test: any non-zero `TINYINT(1)` is true.
return true;
}
if (typeof value === "number" && Number.isInteger(value)) {
return true;
}
return decodeError("tinyint(1)", value);
},
encode: (value) => {
if (typeof value !== "boolean") {
return encodeError("tinyint(1) (a boolean)", value);
}
return value ? "1" : "0";
},
};TINYINT(1) and BOOL, which MySQL spells 1 and 0.
variable
decimalexport const decimal: Codec<string> = {
sqlType: "decimal",
decode: (value) => {
if (typeof value === "string" && DECIMAL.test(value)) {
return value;
}
return decodeError("decimal", value);
},
encode: (value) => {
if (typeof value !== "string" || !DECIMAL.test(value)) {
return encodeError("decimal (a decimal string)", value);
}
return value;
},
};DECIMAL/NUMERIC as its exact decimal string.
function
floatexport function float(sqlType: string): Codec<number> { ... }FLOAT, DOUBLE, and DECIMAL for numeric: "number".
function
textexport function text(sqlType: string): Codec<string> { ... }Character types, DATE, DATETIME, TIMESTAMP, TIME, SET.
variable
stringexport const string: Codec<string> = text("varchar");The character types.
function
bytesexport function bytes(sqlType: string): Codec<Uint8Array> { ... }BLOB, BINARY, VARBINARY, BIT.
variable
jsonexport const json: Codec<JsonValue> = {
sqlType: "json",
decode: (value) => jsonFromText(value),
encode: (value) => jsonParam(value),
};JSON.
variable
unknownexport const unknown: Codec<mixed> = {
sqlType: "unknown",
decode: (value) => value,
encode: (value) => {
if (value === null || typeof value === "string" || value instanceof Uint8Array) {
return value;
}
if (typeof value === "number" || typeof value === "bigint") {
return String(value);
}
if (typeof value === "boolean") {
return value ? "1" : "0";
}
return jsonParam(value);
},
};A result sqlc could not type.
function
enumerationexport function enumeration<T extends string>(
sqlType: string,
values: $ReadOnlyArray<T>,
): Codec<T> { ... }An ENUM(…) column, from its values in declaration order.
function
mapexport function map<T, U>(
codec: Codec<T>,
decode: (value: T) => U,
encode: (value: U) => T,
): Codec<U> { ... }An override's codec: decode narrows what codec read, encode widens a value back to what codec writes.
function
nullableexport function nullable<T>(codec: Codec<T>, value: mixed): T | null { ... }Decode a nullable column.
function
paramexport function param<T>(codec: Codec<T>, value: T | null): MysqlParam { ... }Encode a nullable parameter.
@uniflowed/sql/sqlitetype
Codecexport type Codec<T> = {|
readonly sqlType: string,
readonly decode: (value: mixed) => T,
readonly encode: (value: T) => SqlParam,
|};How one declared type becomes a Flow value and back.
variable
integerexport const integer: Codec<number> = {
sqlType: "INTEGER",
decode: (value) => {
if (typeof value === "number" || typeof value === "bigint") {
return safeInteger("INTEGER", value);
}
return decodeError("INTEGER", value);
},
encode: (value) => integerParam("INTEGER (an integer within ±2^53)", value),
};INTEGER as a number, which throws past 2^53 instead of rounding.
variable
integerAsBigintexport const integerAsBigint: Codec<bigint> = {
sqlType: "INTEGER",
decode: (value) => bigintFrom("INTEGER", value),
encode: (value) => bigintParam("INTEGER (a bigint)", value),
};INTEGER as a bigint, for sqliteInteger: "bigint".
function
realexport function real(sqlType: string): Codec<number> { ... }REAL, DOUBLE, FLOAT, and NUMERIC/DECIMAL, which SQLite stores as one or an INTEGER.
variable
booleanexport const boolean: Codec<boolean> = {
sqlType: "BOOLEAN",
decode: (value) => {
if (value === 0 || value === 0n) {
return false;
}
if (value === 1 || value === 1n) {
return true;
}
return decodeError("BOOLEAN (0 or 1)", value);
},
encode: (value) => {
if (typeof value !== "boolean") {
return encodeError("BOOLEAN (a boolean)", value);
}
return value ? 1 : 0;
},
};BOOLEAN: SQLite stores 0 and 1.
function
textexport function text(sqlType: string): Codec<string> { ... }TEXT and the types SQLite stores as text: VARCHAR, DATE, DATETIME, TIMESTAMP.
variable
stringexport const string: Codec<string> = text("TEXT");TEXT.
variable
blobexport const blob: Codec<Uint8Array> = {
sqlType: "BLOB",
decode: (value) => bytesFrom("BLOB", value),
encode: (value) => bytesParam("BLOB (a Uint8Array)", value),
};BLOB.
variable
jsonexport const json: Codec<JsonValue> = {
sqlType: "JSON",
decode: (value) => jsonFromText(value),
encode: (value) => jsonParam(value),
};JSON and JSONB (sqlc reads the latter through json()), stored as text.
variable
unknownexport const unknown: Codec<mixed> = {
sqlType: "unknown",
decode: (value) => value,
encode: (value) => {
if (
value === null ||
typeof value === "string" ||
typeof value === "number" ||
typeof value === "bigint" ||
value instanceof Uint8Array
) {
return value;
}
if (typeof value === "boolean") {
return value ? 1 : 0;
}
return jsonParam(value);
},
};A declared type with no affinity uf can type, or a result sqlc could not.
function
enumerationexport function enumeration<T extends string>(
sqlType: string,
values: $ReadOnlyArray<T>,
): Codec<T> { ... }A CHECK (x IN (…))-style enum sqlc was told about through an override.
function
mapexport function map<T, U>(
codec: Codec<T>,
decode: (value: T) => U,
encode: (value: U) => T,
): Codec<U> { ... }An override's codec: decode narrows what codec read, encode widens a value back to what codec writes.
function
nullableexport function nullable<T>(codec: Codec<T>, value: mixed): T | null { ... }Decode a nullable column.
function
paramexport function param<T>(codec: Codec<T>, value: T | null): SqlParam { ... }Encode a nullable parameter.
@uniflowed/sql/node-sqliteinterface
NodeSqliteStatementexport interface NodeSqliteStatement {
all(...params: $ReadOnlyArray<SqlParam>): $ReadOnlyArray<mixed>;
run(...params: $ReadOnlyArray<SqlParam>): {
readonly changes: number | bigint,
readonly lastInsertRowid: number | bigint,
...
};
setReadBigInts(enabled: boolean): void;
setReturnArrays(enabled: boolean): void;
}The part of node:sqlite's StatementSync this uses.
interface
NodeSqliteDatabaseexport interface NodeSqliteDatabase {
prepare(text: string): NodeSqliteStatement;
}The part of node:sqlite's DatabaseSync this uses.
function
fromNodeSqliteexport function fromNodeSqlite(
database: NodeSqliteDatabase,
options: NodeSqliteOptions = {},
): Queryable { ... }A [Queryable] over one DatabaseSync.
@uniflowed/sql/bun-sqliteinterface
BunSqliteStatementexport interface BunSqliteStatement {
values(...params: $ReadOnlyArray<SqlParam>): $ReadOnlyArray<mixed>;
run(...params: $ReadOnlyArray<SqlParam>): {
readonly changes: number | bigint,
readonly lastInsertRowid: number | bigint,
...
};
safeIntegers(enabled: boolean): mixed;
}The part of bun:sqlite's Statement this uses.
interface
BunSqliteDatabaseexport interface BunSqliteDatabase {
prepare(text: string): BunSqliteStatement;
}The part of bun:sqlite's Database this uses.
function
fromBunSqliteexport function fromBunSqlite(
database: BunSqliteDatabase,
options: BunSqliteOptions = {},
): Queryable { ... }A [Queryable] over one bun:sqlite Database.
@uniflowed/sql/better-sqlite3interface
BetterSqlite3Statementexport interface BetterSqlite3Statement {
readonly reader: boolean;
all(...params: $ReadOnlyArray<SqlParam>): $ReadOnlyArray<mixed>;
run(...params: $ReadOnlyArray<SqlParam>): {
readonly changes: number,
readonly lastInsertRowid: number | bigint,
...
};
raw(enabled: boolean): mixed;
safeIntegers(enabled: boolean): mixed;
}The part of better-sqlite3's Statement this uses.
interface
BetterSqlite3Databaseexport interface BetterSqlite3Database {
prepare(text: string): BetterSqlite3Statement;
}The part of better-sqlite3's Database this uses.
function
fromBetterSqlite3export function fromBetterSqlite3(
database: BetterSqlite3Database,
options: BetterSqlite3Options = {},
): Queryable { ... }A [Queryable] over one better-sqlite3 Database.
@uniflowed/sql/d1interface
D1Statementexport interface D1Statement {
bind(...params: $ReadOnlyArray<mixed>): D1Statement;
raw(): Promise<$ReadOnlyArray<mixed>>;
run(): Promise<{
readonly meta: { readonly changes?: number, readonly last_row_id?: number, ... },
...
}>;
}The part of a D1 prepared statement this uses.
interface
D1Databaseexport interface D1Database {
prepare(text: string): D1Statement;
}The part of a D1 database binding this uses.
function
fromD1export function fromD1(database: D1Database): Queryable { ... }A [Queryable] over a D1 binding.
@uniflowed/sql/pgliteinterface
PGliteDatabaseexport interface PGliteDatabase {
query(
text: string,
params: $ReadOnlyArray<SqlParam>,
options: {|
readonly rowMode: "array",
readonly parsers: { readonly [string]: (value: string) => mixed },
readonly serializers: { readonly [string]: (value: mixed) => mixed },
|},
): Promise<{ readonly rows: $ReadOnlyArray<mixed>, readonly affectedRows?: number, ... }>;
readonly parsers: { readonly [string]: mixed };
readonly serializers: { readonly [string]: mixed };
}The part of a PGlite instance this uses.
function
fromPGliteexport function fromPGlite(database: PGliteDatabase): Queryable { ... }A [Queryable] over one PGlite database.
@uniflowed/sql/pginterface
PgClientexport interface PgClient {
query(config: PgQuery): Promise<PgResult>;
}A connected pg.Client or a client checked out of a pool.
interface
PgPoolClientexport interface PgPoolClient extends PgClient {
release(error?: mixed): void;
}A client checked out of a pg.Pool.
interface
PgPoolexport interface PgPool {
query(config: PgQuery): Promise<PgResult>;
connect(): Promise<PgPoolClient>;
}A pg.Pool.
function
fromPgClientexport function fromPgClient(client: PgClient): Queryable { ... }A [Queryable] over one connected pg.Client, which it serialises.
function
fromPgPoolexport function fromPgPool(pool: PgPool): Queryable { ... }A [Queryable] over a pg.Pool.
@uniflowed/sql/postgresinterface
PostgresQueriesexport interface PostgresQueries {
unsafe(
text: string,
params: $ReadOnlyArray<mixed>,
options?: {| readonly prepare?: boolean |},
): Unsafe;
typed(value: SqlParam, oid: number): mixed;
}What postgres.js's Sql and its transaction handles have in common.
interface
PostgresTransactionexport interface PostgresTransaction extends PostgresQueries {
savepoint<T>(body: (tx: PostgresTransaction) => Promise<T>): Promise<T>;
}A transaction handle, as begin and savepoint pass one.
interface
PostgresSqlexport interface PostgresSql extends PostgresQueries {
begin<T>(body: (tx: PostgresTransaction) => Promise<T>): Promise<T>;
}A postgres.js Sql instance.
function
fromPostgresexport function fromPostgres(sql: PostgresSql): Queryable { ... }A [Queryable] over a postgres.js Sql.
@uniflowed/sql/mysql2type
Mysql2Fieldexport type Mysql2Field = {
readonly type: string,
string(encoding?: string): string | null,
...
};What a typeCast function is handed for one column.
interface
Mysql2Connectionexport interface Mysql2Connection {
execute(options: Mysql2Options): Promise<[Mysql2Result, mixed]>;
query(options: Mysql2Options): Promise<[Mysql2Result, mixed]>;
}A mysql2/promise connection.
interface
Mysql2PoolConnectionexport interface Mysql2PoolConnection extends Mysql2Connection {
release(): void;
}A connection checked out of a mysql2/promise pool.
interface
Mysql2Poolexport interface Mysql2Pool extends Mysql2Connection {
getConnection(): Promise<Mysql2PoolConnection>;
}A mysql2/promise pool.
function
typeCastexport function typeCast(field: Mysql2Field, next: () => mixed): mixed { ... }JSON and DECIMAL columns as the text MySQL sent; everything else as the statement's options already ask. JSON arrives with the binary charset, so it is read as UTF-8, which is what the JSON type stores.
function
fromMysql2Poolexport function fromMysql2Pool(pool: Mysql2Pool): Queryable { ... }A [Queryable] over a mysql2/promise pool.