Hello. I am building a nextjs e-commerce
Hello. I am building a nextjs e-commerce site and I will deploy it in cloudflare pages. I am writing the backend in nextjs for the first time. I am having issue in communication to the db. I am using supabase's pg database. I created a hyperdrive for the pg database. Now in the next js project I want to use the connection with Kysely. I can't find any proper docs or example on how to create the client.
I can't use supabase's client side library since it doesn't support joins without FK. From my research I found that hyperdrive is the only way to acheive it, but I am having trouble setting it up. Can someone please help? TIA 🙏
4 Replies
You should be able to use Kysely with the Hyperdrive connection string, similarly to how we have docs on Drizzle and Prisma ORM https://developers.cloudflare.com/hyperdrive/examples/connect-to-postgres/postgres-drivers-and-libraries/drizzle-orm/
Cloudflare Docs
Drizzle ORM
Drizzle ORM is a lightweight TypeScript ORM with a focus on type safety. This example demonstrates how to use Drizzle ORM with PostgreSQL via Cloudflare Hyperdrive in a Workers application.
hmmm. checking it now. hopefully I can make it work.
https://pastecode.io/s/8qbwri88
I tried to set it up like this.
wrangler.toml has the binding
db.ts has the client creation code
then I use the client in the page.tsx.
When I run npx open-next build. I get this error ->
./node_modules/pg-connection-string/index.js:81:1
Module not found: Can't resolve 'fs'
79 |
80 | // Only try to load fs if we expect to read from the disk
81 | const fs = config.sslcert config.sslkey config.sslrootcert ? require('fs') : null| ^ 82 | 83 | if (config.sslcert) { 84 | config.ssl.cert = fs.readFileSync(config.sslcert).toString() https://nextjs.org/docs/messages/module-not-found
@thomasgauvin not getting any clue why it tries to bundle the pg in client side. or maybe it is related to reading ssl certs. do you have any idea regarding this?
just got to know open next doesn't work well in windows. Please ignore for now