TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/NikolayS/PgQue/llms.txt
Use this file to discover all available pages before exploring further.
pgque npm package is a thin, idiomatic TypeScript wrapper over the pgque.* SQL functions, built on node-postgres (pg). Each send, receive, and ack call runs in its own implicit transaction via pg.Pool, satisfying the snapshot rule automatically.
Installation
Database permissions
Quickstart
Client API
| Method | Returns | Description |
|---|---|---|
connect(dsn, poolOptions?) | Promise<PgqueClient> | Connect via pg.Pool. |
client.send(queue, event) | Promise<bigint> | Publish one event. |
client.sendBatch(queue, type, payloads) | Promise<bigint[]> | Publish a batch atomically. |
client.receive(queue, consumer, max?) | Promise<Message[]> | Fetch up to max messages (default 100). |
client.ack(batchId) | Promise<number> | Finish the batch. Returns 1 success, 0 stale. |
client.nack(batchId, msg, opts?) | Promise<void> | Retry with delay or route to DLQ. |
client.subscribe(queue, consumer) | Promise<number> | Register consumer. |
client.unsubscribe(queue, consumer) | Promise<number> | Remove consumer. |
client.ticker(queue) | Promise<bigint | null> | Tick one queue. |
client.tickerAll() | Promise<number> | Tick all queues. |
client.forceNextTick(queue) | Promise<bigint | null> | For testing. |
client.newConsumer(queue, name, opts?) | Consumer | Create a high-level poll loop. |
client.close() | Promise<void> | Drain the pool. |
bigint IDs
Message.msgId, Message.batchId, and the return values of send(), sendBatch(), ticker(), and forceNextTick() are JavaScript bigint to match PostgreSQL bigint without precision loss. The int8 → bigint parser is registered only on pgque’s internal pool — it does not affect other pg.Pool or pg.Client instances in the same process.
Typed errors
PgqueError. Types: PgqueConnectionError, PgqueQueueNotFoundError, PgqueConsumerNotFoundError, PgqueSqlError (with cause).
Cooperative consumers (experimental)
subscribeSubconsumer, unsubscribeSubconsumer, receiveCoop, touchSubconsumer.
Transactions
pg.Pool.query satisfies the snapshot rule transparently — each send/receive/ack runs in its own implicit transaction. The footgun is client.rawPool: do not wrap pgque.send and pgque.receive in one shared pool client transaction. See how PgQue works for the snapshot rule.