Store.postgres
Postgres storage
Creates an atomic store from a Postgres client's query method.
Usage
store.ts
import { Store } from 'mppx'
import { Pool } from 'pg'
const db = new Pool({ connectionString: process.env.DATABASE_URL })
const store = Store.postgres(db)
console.log(await Store.tryClaim(store, 'request:customer-42:1', Date.now() + 60_000))
trueSupports pg, Neon's query clients, @vercel/postgres, Supabase Postgres connections, and PGlite. For Postgres.js unsafe, use Store.sql.
Return type
type ReturnType = Store.AtomicStore- Provides
get,put,delete, atomicupdate, and replay claims; see the AtomicStore contract. - Keep update callbacks synchronous and side-effect-free: conflicts rerun them.
Parameters
client
- Type:
Store.postgres.Client
Client exposing query(text: string, values: unknown[]): Promise<{ rows: Store.sql.Row[] } | Store.sql.Row[]>, including RETURNING rows.
options (optional)
- Type:
Store.sql.Options
| Property | Type | Default | Description |
|---|---|---|---|
createTable (optional) | boolean | true | Creates the table on first use; set false for a migration-managed table. |
keyPrefix (optional) | string | None | Prefix for every backing key. |
maxAttempts (optional) | number | 32 | Maximum compare-and-swap attempts per update. |
table (optional) | string | 'mppx_store' | Valid name or schema.name identifier. |
See Store.sql for schema, migrations, serialization, and conflict errors.