graphile / worker

High performance Node.js/PostgreSQL job queue (also suitable for getting jobs generated by PostgreSQL triggers/functions out into a different work queue)
http://worker.graphile.org/
MIT License
1.81k stars 101 forks source link

postgres.js pool support #441

Open DanielFGray opened 7 months ago

DanielFGray commented 7 months ago

Feature description

I think Worker should ideally be able to accept a pool from either node-postgres or postgres.js

Motivating example

I am currently working on a project that connects to the db using postgres.js, my app does not use node-postgres anywhere, and ideally I shouldn't be required to add another adapter.

Breaking changes

I don't believe this should constitute a breaking change

Supporting development

I [tick all that apply]:

DanielFGray commented 7 months ago

Happy to help where I can on this, though I fear my attempt wouldn't quite be up to par with the usual Graphile standards

benjie commented 7 months ago

Ideally we'd use an adaptor system like with PostGraphile V5 (or, more specifically, @dataplan/pg) such that we can use any client for which there is an adaptor. We have graphile-config for config, and @graphile/logger for logging, so we should probably extract the adaptors from @dataplan/pg and make @graphile/pg or similar that all our projects can use. In the mean time, we use very few of the Postgres methods, so you could probably create a stub pool/client combo with anything that quacks sufficiently like Pool/Client that we'd believe that's what it was. Pool.connect/Pool.end/Pool.on('error')/Pool.on('connect') and PoolClient.query/PoolClient.on('error')/PoolClient.on('notification') are the main things I can think of off-hand.

DanielFGray commented 7 months ago

for whatever it's worth (and mostly to anyone else who might stumble on this issue), I found postgres-bridge which I expected to stub the necessary bits, but I would get either TypeError: pgPool.query is not a function or TypeError: pgPool.connect is not a function depending on if I pass the bridge instance directly as a pool, or the result of await bridge.connect() and I couldn't quite narrow it down any further

for now, sticking with using pg for worker and postgres for everything else