Connecting to CockroachDB serverless using pg via workers
1. Created a npx wrangler init .
2. Then "npm install pg" and added the query code into index.js
3. then, npx wrangler dev, got compatibility errors, and got suggestions to add "node_compat = true", and I did, those errors disappeared
4. Then again ran "npx wrangler dev", got error ' could not resolve "pg-native" '. And this is where I'm struck. I ran same code in normal js and it worked, but I don't know why is it asking "pg-native", and also I tried to install it locally and globally, and it won't get installed.
5. What to do?
3 Replies
any other immediate solution?
This is out now, correct?
https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets
and
https://developers.cloudflare.com/workers/tutorials/postgres/
TCP sockets · Cloudflare Workers docs
Use the
connect()
API to create outbound TCP connections from Workers.Connect to a PostgreSQL database with Cloudflare Workers · Cloudfla...
In this tutorial, you will learn how to create a Cloudflare Workers application and connect it to a PostgreSQL database using TCP Sockets. The Workers …
Great! Thanks. QQ - I am trying to deploy using Astro (so pages rather than a Worker). I want to use
pg
in an API route like below.
Where do I specify I want to use Node compatibility? I see Settings -> Functions -> Compatibility flags in the dashboard UI. I guess I am not clear on
1. Do I just add node_compat
in the UI? (or is it nodejs_compt
)
2. Have I actually understood the process correctly that an Astro API route will be converted to a Pages Function?
The error I get on deploy is The package "net" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.