createPgStateAdapter
createPgStateAdapter<
TTxContext,TIdType>(options):Promise<StateAdapter<TTxContext,TIdType> &object>
Defined in: packages/postgres/src/state-adapter/state-adapter.pg.ts:426
Create a state adapter backed by PostgreSQL. Returns the adapter with a
migrateToLatest() method for schema migrations.
Type Parameters
Section titled “Type Parameters”TTxContext
Section titled “TTxContext”TTxContext extends BaseTxContext
TIdType
Section titled “TIdType”TIdType extends string = `${string}-${string}-${string}-${string}-${string}`
Parameters
Section titled “Parameters”options
Section titled “options”PostgreSQL state adapter configuration.
generateId?
Section titled “generateId?”() => TIdType = ...
Function to generate new job IDs. Must return unique values — collisions are a hard error (the unique constraint rejects duplicates).
Default Value
() => crypto.randomUUID()
idType?
Section titled “idType?”string = "uuid"
SQL type for the primary key column.
Default Value
"uuid"
schema?
Section titled “schema?”string = "public"
PostgreSQL schema for all tables.
Default Value
"public"
stateProvider
Section titled “stateProvider”PgStateProvider<TTxContext>
PostgreSQL state provider wrapping the database connection.
tablePrefix?
Section titled “tablePrefix?”string = "queuert_"
Prefix for all table names.
Default Value
"queuert_"
validateId?
Section titled “validateId?”(id) => boolean
Predicate returning true if the ID is acceptable. Runs on both generated
and caller-supplied IDs; failures throw InvalidJobIdError.
Returns
Section titled “Returns”Promise<StateAdapter<TTxContext, TIdType> & object>
Throws
Section titled “Throws”Error if schema, tablePrefix or idType is not a valid SQL identifier.