PostgresIdempotencyStore
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:142
IdempotencyStore backed by Postgres (pg) — a drop-in
replacement that shares state across instances without a separate Redis.
Create the table once with createIdempotencyTableSql. Atomicity of
setIfAbsent comes from a conditional INSERT … ON CONFLICT … DO UPDATE: an absent key is inserted, an expired key is atomically replaced,
and a live conflict is left untouched. Completion/release also compare
claim_id in the same SQL statement, so a stale execution cannot mutate a
newer claim. The table name is validated as a plain SQL identifier (it is
interpolated, not parameterized); all values are passed as bound parameters.
Example
Section titled “Example”import { Pool } from 'pg';const pool = new Pool({ connectionString: process.env.DATABASE_URL });await pool.query(createIdempotencyTableSql());const store = new PostgresIdempotencyStore(pool);Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PostgresIdempotencyStore(
db,options?):PostgresIdempotencyStore
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:145
Parameters
Section titled “Parameters”options?
Section titled “options?”PostgresIdempotencyStoreOptions = {}
Returns
Section titled “Returns”PostgresIdempotencyStore
Methods
Section titled “Methods”completeIfOwned()
Section titled “completeIfOwned()”completeIfOwned(
key,claimId,record,ttlMs):Promise<boolean>
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:191
Atomically replaces the live in_progress record with record only when
the existing record is still owned by claimId.
Parameters
Section titled “Parameters”string
claimId
Section titled “claimId”string
record
Section titled “record”number
Returns
Section titled “Returns”Promise<boolean>
true when this claim completed its own record; false when the
claim expired, was replaced, or was otherwise no longer owned by the caller.
Implementation of
Section titled “Implementation of”IdempotencyStore.completeIfOwned
delete()
Section titled “delete()”delete(
key):Promise<void>
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:253
Unconditional delete for administrative or custom use. Pipeline failure release uses deleteIfOwned, not this method.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”deleteIfOwned()
Section titled “deleteIfOwned()”deleteIfOwned(
key,claimId):Promise<boolean>
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:218
Atomically removes the live record only when it is still owned by
claimId. Used by releaseOnError so a stale failure cannot delete a
newer execution’s claim.
Parameters
Section titled “Parameters”string
claimId
Section titled “claimId”string
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”IdempotencyStore.deleteIfOwned
get(
key):Promise<IdempotencyRecord|undefined>
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:152
Returns the live (non-expired) record for key, or undefined if there is
none.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<IdempotencyRecord | undefined>
Implementation of
Section titled “Implementation of”set(
key,record,ttlMs):Promise<void>
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:230
Unconditional overwrite for administrative or custom use. Pipeline execution completion uses completeIfOwned, not this method.
Parameters
Section titled “Parameters”string
record
Section titled “record”number
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”setIfAbsent()
Section titled “setIfAbsent()”setIfAbsent(
key,record,ttlMs):Promise<boolean>
Defined in: packages/pipeline-idempotency/src/stores/postgres.store.ts:165
Atomically stores record only if no live record exists for key.
Parameters
Section titled “Parameters”string
record
Section titled “record”number
Returns
Section titled “Returns”Promise<boolean>
true if the key was claimed by this call, false if a live
record already existed.