postgres in pages
how can i use postgres using sveltekit with pages and drizzle ORM?
im using
pg
atm but im getting these errors when building;
5 Replies
Did you find a solution to this?
you'll need to connect at the request level, not app level, serverless pages can't maintain a db connect
also those libs dont work w cf workers, no fs access, there are other ways to connect to postgres, like neon
Had the same issues yesterday, this seems it would work (at least on a theoretical level, haven't tried it out yet)
Have you tried a serverless client https://orm.drizzle.team/docs/connect-vercel-postgres ? NOT TESTED
Drizzle ORM - Vercel Postgres
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
My recomendation is to use Cloudflare Hyperdrive. It manages a kind of connection pool between workers and your database. Also, postgres-js driver is more recommended for serverless environments. Note that you need to set https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag.