Skip to content

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.

TTxContext extends BaseTxContext

TIdType extends string = `${string}-${string}-${string}-${string}-${string}`

PostgreSQL state adapter configuration.

() => 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()

string = "uuid"

SQL type for the primary key column.

Default Value

"uuid"

string = "public"

PostgreSQL schema for all tables.

Default Value

"public"

PgStateProvider<TTxContext>

PostgreSQL state provider wrapping the database connection.

string = "queuert_"

Prefix for all table names.

Default Value

"queuert_"

(id) => boolean

Predicate returning true if the ID is acceptable. Runs on both generated and caller-supplied IDs; failures throw InvalidJobIdError.

Promise<StateAdapter<TTxContext, TIdType> & object>

Error if schema, tablePrefix or idType is not a valid SQL identifier.