worker
worker copied to clipboard
postgres.js pool support
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
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
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.
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