I have created a local postgresql database and I'm trying to access it on a serverless backend with Cloudflare Workers and Hono JS framework.
Since it is serverless logically I have to use data proxy, I link my database
prisma://postgres://HP:password@localhost:5432/database
but I get this error: No valid API key found in the datasource URL. Obviously I can't create an API key on cloud.prisma.io since my database is locally. When I link it like this:
postgres://HP:password@localhost:5432/database
I am able to run npx prisma studio and take a look at all my models and its corresponding data. But I get this error when running the project in this case : Datasource URL must use prisma:// protocol when --data-proxy is used. My first question would be, is it possible to connect to a local database and if yes what may I be doing wrong?
If somebody encounters the same difficulty this is the solution to it:
install and use ngrok
run this command: ngrok tcp 5432 (5432 is my port)
A url similar to this will be generated : tcp://0.tcp.ngrok.io:12345
postgres://user:[email protected]:12345/database
Take this link and create connection string in cloud.prisma.io
Use the connection string in your project and you're good to go.