Skip to main content

@flow-state-dev/store-postgres/host

Interfaces​

QueryExecutor​

Methods​

beginTx()?​
beginTx?(): Promise<TxClient>;

Begin an interactive transaction bound to a single underlying connection. Required by createPostgresScheduleIndex (and any other feature needing SELECT ... FOR UPDATE SKIP LOCKED semantics inside a transaction). Optional on the interface so executors that cannot pin a connection (e.g. arbitrary HTTP-proxied query surfaces) remain valid for the rest of the store API.

Returns​

Promise<TxClient>

query()​
query(text, values?): Promise<QueryResult>;
Parameters​
text​

string

values?​

unknown[]

Returns​

Promise<QueryResult>


TxClient​

A transaction handle. query runs on the pinned connection. The caller MUST eventually call exactly one of commit or rollback to release the connection back to the pool.

Methods​

commit()​
commit(): Promise<void>;
Returns​

Promise<void>

query()​
query(text, values?): Promise<QueryResult>;
Parameters​
text​

string

values?​

unknown[]

Returns​

Promise<QueryResult>

rollback()​
rollback(): Promise<void>;
Returns​

Promise<void>

Type Aliases​

PostgresBus​

type PostgresBus = ChangeBus & object;

The Postgres bus, with the close its registry calls before ending the pools.

Type Declaration​

close()​
close(): Promise<void>;

Stop the ping and hand the listening connection back. Resolves once it is back.

Returns​

Promise<void>


PostgresStoreRegistry​

type PostgresStoreRegistry = StoreRegistry & object;

@flow-state-dev/store-postgres/host: what a host or adapter author builds with — the registry factory, the per-store constructors, the schema and transaction helpers, and the Postgres bus type. Public and semver-covered. App code imports postgresStores from @flow-state-dev/store-postgres.

Type Declaration​

bus​
bus: PostgresBus;

The Postgres change bus. It crosses processes while it hears its own ping over the tail pool; without a tail pool it stays in process.

close()​
close(): Promise<void>;

Hand back the bus's listening connection, then drain the pools and disconnect.

Returns​

Promise<void>

Functions​

createPgPoolTx()​

function createPgPoolTx(pool): Promise<TxClient>;

Acquire a pool client, BEGIN, and return a TxClient that pins all subsequent queries to that connection. Caller MUST end with exactly one commit() or rollback(); either releases the client back to the pool.

Parameters​

pool​

Pool

Returns​

Promise<TxClient>


createPostgresActiveRequestRegistry()​

function createPostgresActiveRequestRegistry(executor, options?): ActiveRequestRegistry;

Parameters​

executor​

QueryExecutor

options?​

PostgresActiveRequestRegistryOptions

Returns​

ActiveRequestRegistry


createPostgresCheckpointStore()​

function createPostgresCheckpointStore(executor): CheckpointStore;

Parameters​

executor​

QueryExecutor

Returns​

CheckpointStore


createPostgresContentStore()​

function createPostgresContentStore(executor): ContentStore;

Parameters​

executor​

QueryExecutor

Returns​

ContentStore


createPostgresLeaseStore()​

function createPostgresLeaseStore(executor): LeaseStore;

Parameters​

executor​

QueryExecutor

Returns​

LeaseStore


createPostgresOrgStore()​

function createPostgresOrgStore(executor): OrgStore;

Parameters​

executor​

QueryExecutor

Returns​

OrgStore


createPostgresRequestStore()​

function createPostgresRequestStore(executor, options?): RequestStore;

Parameters​

executor​

QueryExecutor

options?​

CreatePostgresRequestStoreOptions

Returns​

RequestStore


createPostgresResourceStateStore()​

function createPostgresResourceStateStore(executor): ResourceStateStore;

Parameters​

executor​

QueryExecutor

Returns​

ResourceStateStore


createPostgresSessionStore()​

function createPostgresSessionStore(executor): SessionStore;

Parameters​

executor​

QueryExecutor

Returns​

SessionStore


createPostgresStores()​

function createPostgresStores(options): Promise<PostgresStoreRegistry>;

Create a StoreRegistry backed by PostgreSQL. Schema auto-initializes on first call (idempotent), unless skipSchemaInit: true.

Accepts one of:

  • { pool } — a pre-configured pg.Pool
  • { connectionString?, max?, poolOptions?, createPool? } — connection config (pool created internally). When connectionString is omitted, reads from FSD_DB_URL then DATABASE_URL. poolOptions is merged onto the adapter's defaults (caller wins). createPool overrides the Pool constructor (defaults to (cfg) => new pg.Pool(cfg)).
  • { executor } — a QueryExecutor-compatible client (e.g. PGlite for testing)

Pass skipSchemaInit: true (along with any of the above shapes) when migrations run out-of-band — e.g. a deploy-time script that calls createPostgresStores once with skipSchemaInit unset and then await stores.close().

Parameters​

options​

PostgresStoreOptions

Returns​

Promise<PostgresStoreRegistry>


createPostgresSuspensionStore()​

function createPostgresSuspensionStore(executor): SuspensionStore;

Parameters​

executor​

QueryExecutor

Returns​

SuspensionStore


createPostgresUserStore()​

function createPostgresUserStore(executor): UserStore;

Parameters​

executor​

QueryExecutor

Returns​

UserStore


createPostgresWakeStore()​

function createPostgresWakeStore(executor): WakeStore;

Parameters​

executor​

QueryExecutor

Returns​

WakeStore


initializeSchema()​

function initializeSchema(executor): Promise<void>;

Initialize the schema using a QueryExecutor. Each query may run on a different pool connection, so the advisory lock may leak onto an unknown connection. Prefer initializeSchemaWithDedicatedClient when you have direct pg.Pool access.

Parameters​

executor​

QueryExecutor

Returns​

Promise<void>