Skip to content

API

Every export of both entry points, as src/ declares them. Functions take plain options objects; types marked “interface” are structural, so a value of the right shape is accepted.

Export Kind What it is
postgresDatabase(options) function Opens the schema and returns a PostgresDatabase: chord’s SqliteDatabase over a node-postgres pool.
postgresBackend(options) function sqliteBackend(await postgresDatabase(options)) — what openStore/importStore take.
openPostgresStore(options, context) function Publishes a chord store on Postgres: the database, the backend, openStore. Resolves with chord’s ChordStore.
PostgresDatabase class The class behind postgresDatabase. schema is the Postgres schema; close() ends the pool this adapter created (a borrowed pool is left open).
PostgresDatabaseOptions interface What postgresDatabase takes; see Options.
PostgresStoreOptions interface The store’s options: the database’s, plus outbox.
PostgresStore type Awaited<ReturnType<typeof openStore>>, so it follows chord rather than pinning a shape.
DEFAULT_SCHEMA const "chord".
DEFAULT_STATEMENT_TIMEOUT_MS const 30000.
ConnectionLostError class The connection died; this database object is unusable for good. Carries the driver error as cause.
ClosedError class The database or a transaction handle was already closed, or a statement was issued on the database inside its own transaction.
SchemaTooNewError class The schema holds a newer version of this adapter’s own objects. found and supported say which.
UnsupportedSqlError class The dialect layer refused a statement. sql is the statement, and the message carries it too.
CONSTRUCTS const The table of translated constructs, as data — the same list as The SQL dialect layer.
ColumnKind, TableInfo types What the catalogue reports about a table: the column kinds the translator reasons about.
isConnectionLoss(error) function Whether an error is the connection going away rather than the statement being wrong — the predicate behind the latch.
Export Kind What it is
postgresStorage(options, context) function Opens the store, claims the owner’s tables in it, and returns a pi-durable Storage over StoreStorage.
PostgresStorage interface That Storage, plus its store (the chord store) — and its close closes the store too.
PostgresStorageOptions interface The store options plus owner.
// chord-postgres
export function postgresDatabase(options: PostgresDatabaseOptions): Promise<PostgresDatabase>
export function postgresBackend(options: PostgresDatabaseOptions): Promise<Backend>
export function openPostgresStore(options: PostgresStoreOptions, context: Context): Promise<PostgresStore>
export const DEFAULT_SCHEMA = "chord"
export const DEFAULT_STATEMENT_TIMEOUT_MS = 30_000
export class PostgresDatabase {
readonly schema: string
close(): Promise<void>
// plus chord's SqliteDatabase: exec, run, runCounted, get, all, transaction
}
export function isConnectionLoss(error: unknown): boolean

Backend and Context come from @earendil-works/chord, PostgresStore is chord’s ChordStore through Awaited<ReturnType<typeof openStore>>.

chord-postgres/pi-durable
export function postgresStorage(
options: PostgresStorageOptions,
context: Context,
): Promise<PostgresStorage>
export interface PostgresStorage extends Storage {
readonly store: PostgresStore
close(context: Context): Promise<void>
}

Context is @earendil-works/chord/context’s; there is no chord-postgres context of its own. BACKGROUND_CONTEXT from that module is what the examples pass, and it is what a process-level host uses.

All four extend Error with a name set to the class name and a message prefixed chord-postgres:, so a log line says where the failure came from.

Error When What to do
ConnectionLostError a statement, a commit, a rollback or the pool reported the connection going away (SQLSTATE 08xxx, 57P0x, or a socket errno) close the database object and open a new one; retrying on the same object rejects with the same error
ClosedError a call on a closed database, a transaction handle used after its callback settled, or a statement on the database inside its own transaction fix the call order — use the transaction handle inside transaction
SchemaTooNewError the schema’s adapter row records a version above this build’s (found, supported) upgrade chord-postgres
UnsupportedSqlError the dialect layer met a statement it does not recognise (sql carries it) report it: it means chord emits a construct this package has not translated

isConnectionLoss(error) is the predicate all four are classified by; exported because a host that wraps the store may want the same decision.