neondatabase / serverless

Connect to Neon PostgreSQL from serverless/worker/edge functions
https://www.npmjs.com/package/@neondatabase/serverless
MIT License
366 stars 16 forks source link

Support local postgres, consider `pg-cloudflare`? #18

Open ben-xD opened 1 year ago

ben-xD commented 1 year ago

https://www.npmjs.com/package/pg-cloudflare was released 11 days ago. It uses native TCP connections on Cloudflare Workers, since Cloudflare has recently added that capability. https://www.npmjs.com/package/pg

However, this package uses pg, which doesn't take advantage of this.

Adding support for this will mean I can develop offline (in trains, flights) and improves the testability (e.g. just spin a postgres up to run certain tests).

jawj commented 1 year ago

For now, you can run our WebSocket proxy locally (although this does mean changing some settings on the driver). Gal has blogged about this here: https://gal.hagever.com/posts/running-vercel-postgres-locally

It's on my list to see if we can support Cloudflare TCP in the driver too, though.

ben-xD commented 1 year ago

Cool, I've got that working, thanks!

ben-xD commented 1 year ago

Actually I'll re-open because although things work locally, adding support for Cloudflare connect() might be useful/interesting for Neon users.

jawj commented 1 year ago

Sure. Of course, you should also be able to just use pg, but the SCRAM auth may burn CPU time.

TimoWilhelm commented 1 year ago

Is there a way to make the neon function using https fetch available with a local PG instance? I tried the pg proxy mentioned in the post above but I'm guessing this only supports WebSocket Pool right?

jawj commented 1 year ago

@TimoWilhelm Take a look here for instructions on running our proxy locally: https://github.com/neondatabase/serverless/issues/33#issuecomment-1634853042

We do have plans to make this easier (e.g. with a Docker image or via the Neon CLI) in the future. And sooner than that, we have plans to allow embedding a http/WebSocket port in the query string part of the connection URL, so that no additional code is needed.

lukahartwig commented 1 year ago

Just ran into this as well. Until you guys find a better solution would it be possible to improve the error message, pointing you to the documentation about the proxy?

venkatd commented 1 year ago

I would consider this a very high impact improvement for developer experience. It is causing us a lot of friction that our local and test environments no longer work and that we have to ask all of our engineers to resort to frustrating workarounds.

neondb is ALMOST a drop-in replacement... once localhost just works, adopting neondb will become more of a no-brainer for startups

pg-cloudflare does seem promising so you don't have to force users to install a lot of extra things like Docker

mmikhan commented 1 month ago

For now, you can run our WebSocket proxy locally (although this does mean changing some settings on the driver). Gal has blogged about this here: https://gal.hagever.com/posts/running-vercel-postgres-locally

It's on my list to see if we can support Cloudflare TCP in the driver too, though.

This no longer works in the current version ~0.10* but only does at ~0.9.*~. Even Vercel official Postgres local guide is outdated