Skip to content

@queuert/postgres

const stateAdapter = await createPgStateAdapter({
stateProvider: PgStateProvider, // You implement this
schema?: string, // PostgreSQL schema name (default: "public")
tablePrefix?: string, // Table name prefix (default: "queuert_")
idType?: string, // SQL type for job IDs (default: "uuid")
idDefault?: string, // SQL DEFAULT expression (default: "gen_random_uuid()")
});

Returns Promise<PgStateAdapter>.

PgStateAdapterStateAdapter extended with migration support:

type PgStateAdapter = StateAdapter & {
migrateToLatest: () => Promise<MigrationResult>;
};

PgStateProvider — you implement this to bridge your PostgreSQL client:

type PgStateProvider<TTxContext> = {
withTransaction: <T>(fn: (txCtx: TTxContext) => Promise<T>) => Promise<T>;
withSavepoint?: <T>(txCtx: TTxContext, fn: (txCtx: TTxContext) => Promise<T>) => Promise<T>;
executeSql: (options: {
txCtx?: TTxContext;
sql: string;
params?: unknown[];
}) => Promise<unknown[]>;
};

withSavepoint is optional. When not provided, the adapter uses raw SAVEPOINT SQL via executeSql. Override it when your driver tracks transaction state client-side (e.g. postgres.js — use txCtx.sql.savepoint()).

const notifyAdapter = await createPgNotifyAdapter({
notifyProvider: PgNotifyProvider, // You implement this
channelPrefix?: string, // Channel prefix (default: "queuert")
});

Returns Promise<NotifyAdapter>.

PgNotifyProvider — you implement this to bridge your PostgreSQL client:

type PgNotifyProvider = {
publish: (channel: string, message: string) => Promise<void>;
subscribe: (
channel: string,
onMessage: (message: string) => void,
) => Promise<() => Promise<void>>;
};
type MigrationResult = {
applied: string[]; // Migrations applied in this run
skipped: string[]; // Already-applied migrations
unrecognized: string[]; // Unknown migrations found in the database
};