Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slonik support @neondatabase/serverless (postgres over HTTP / websockets) - pg compatible #642

Open
firxworx opened this issue Sep 1, 2024 · 5 comments

Comments

@firxworx
Copy link

firxworx commented Sep 1, 2024

Desired Behavior

Slonik project offers official guidance in docs and/or a bridge/adapter to @neondatabase/serverless which, like slonik, is based on pg and intended to serve as a drop-in replacement.

This would enable use of slonik in serverless/edge environments to connect to postgres over HTTP or websockets and take advantage over various performance and scalability benefits in this deployment context.

Motivation

Honestly I think it seems like a good fit and future forward step for Slonik -- it opens the door to more applications, larger community, broader and more varied ecosystem with wider range of expertise.

I wonder if you reach out to the right people at Neon they may even sponsor this :)

Serverless/edge type environments aren't going anywhere. New breed devs are brought up on CloudFlare, Vercel, Netlify and others, plus AWS is going to be a rock for the foreseeable future not to mention Azure + Google. Neon is frequently suggested as the way to go for serverless/edge + postgres.

Neon is an innovator (e.g. branching) and a lot of their developments are open source so they will only influence more in the foreseeable future.

Other popular database libraries for Node / TypeScript already have official adapters for Neon serverless including Drizzle.

If you haven't tried Neon I'd suggest trying their generous free tier.

Implementation

Slonik already has a bridge/adapter for postgres.js which has way more differences and nuances than something based on pg and intended to be drop-in.

@gajus
Copy link
Owner

gajus commented Sep 24, 2024

This would belong in community packages.

I will leave this issue open in case anyone wants to contribute a bridge. I will add it to Slonik's README.

@capaj
Copy link

capaj commented Oct 7, 2024

@gajus what about support for https://github.com/electric-sql/pglite ?
Does that also belong to community packages?
If so, can you give any pointers where to start when developing a "bridge"?

@firxworx
Copy link
Author

firxworx commented Oct 7, 2024

@gajus is there a repo for community packages or a contribution doc / process? Like if I or another dev were to implement something where would we PR / where would you add it (e.g. like a ./packages/community in this repo or another repo)?

Or did you mean that if I build something to publish it independently vs. contribute to something under the slonik banner?

I searched down the README for "community" and "contribut..." and didn't find anything. A CONTRIBUTING.md might be helpful.

I looked at the code for https://github.com/gajus/slonik/blob/main/packages/pg-driver/src/factories/createPgDriverFactory.ts and at least on the surface it looks do-able. To use the custom driver I assume I would use the driverFactory client configuration option to specify it.

@gajus
Copy link
Owner

gajus commented Nov 11, 2024

Or did you mean that if I build something to publish it independently vs. contribute to something under the slonik banner?

Just that.

@firxworx
Copy link
Author

OK I wrote a package to support @neondatabase/serverless based on the @slonik/pg-driver package as a reference. It is working without issue in a demo CRUD API.

When I find some more time I will review it, make it public, and publish it to npm. As far as I can tell from searching GitHub it might be the first public independent driver factory for slonik created using @slonik/driver.

I'm not sure the ideal way to test it. Both @slonik/driver and @slonik/pg-driver only have stub tests however I know slonik itself has thorough integration tests that cover the bases. I suppose I can always use my Neon account with the demo API to enable a scripted integration/e2e-like test. Input/ideas welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants