worker icon indicating copy to clipboard operation
worker copied to clipboard

postgres.js pool support

Open DanielFGray opened this issue 1 year ago • 4 comments

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]:

  • [ ] am interested in building this feature myself
  • [x] am interested in collaborating on building this feature
  • [x] am willing to help testing this feature before it's released
  • [x] am willing to write a test-driven test suite for this feature (before it exists)
  • [x] am a Graphile sponsor ❤️
  • [ ] have an active support or consultancy contract with Graphile

DanielFGray avatar Mar 02 '24 18:03 DanielFGray

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

DanielFGray avatar Mar 02 '24 19:03 DanielFGray

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.

benjie avatar Mar 02 '24 21:03 benjie

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

DanielFGray avatar Mar 21 '24 19:03 DanielFGray