Repository navigation
docs(examples/prisma): update Prisma setup for Prisma ORM 8 - #922
ankur-arch wants to merge 3 commits into
Conversation
Rewrite the Prisma Postgres section for Prisma ORM 8 (orm init, @prisma/orm-postgres, nodejs_compat, one client per request), pin the D1 section to Prisma ORM 7 with the current generator and CLI flags, add a short Prisma Compute pointer, and fix the resource links.
| Here is an example of how you can use this function in your project: | ||
| app.use(async (c, next) => { | ||
| const db = postgres<Contract>({ | ||
| contractJson, |
There was a problem hiding this comment.
The current postgres options do not accept contractJson and should be contract. The document show fhe following:
const contract = contractFromJson<Contract>(contractJson);
export default {
async fetch(request, env, ctx): Promise<Response> {
const path = new URL(request.url).pathname;
if (path === "/favicon.ico") return new Response("Not found", { status: 404 });
const db = postgres({ contract, url: env.DATABASE_URL });There was a problem hiding this comment.
Thanks @yusukebe, good catch! Fixed in fa05b8d.
The example now follows the Prisma Cloudflare Workers guide. It converts the JSON contract once using contractFromJson<Contract>() and reuses it when creating the client in middleware.
I also tested it locally with wrangler dev against Prisma Postgres. Creating a user and fetching it on the next request both worked.
Could you take another look?
There was a problem hiding this comment.
@yusukebe following up on this, icymi! Thanks in advance 🙌
|
Hey @ankur-arch Thank you for the PR! Nice. I left a comment. Please check it. |
Hi Hono team! This updates the Prisma on Cloudflare Workers example, which still showed the Accelerate-based setup that no longer works with current Prisma releases.
What changed
npx prisma@latest orm init, the@prisma/orm-postgrespackage and thenodejs_compatflag. The example is a Hono middleware that creates one client per request and closes it withc.executionCtx.waitUntil, plusGET /usersandPOST /usersroutes. It follows the Prisma docs guide for Cloudflare Workers.prisma@7and@prisma/client@7(plainnpx prismainstalls 8 today). It drops thedriverAdapterspreview flag, switches to theprisma-clientgenerator withruntime = "cloudflare", changes--to-schema-datamodelto--to-schema, fixes the client import path so it matches the generator output, and adds awrangler.jsonctab since the template now creates that file. It follows the Prisma Cloudflare D1 guide.How I tested
I followed the page step by step in fresh
npm create hono@latest(cloudflare-workers) projects with Wrangler 4.151:prisma8.0.0-rc.24,@prisma/orm-postgres8.0.0-rc.18): created a database withnpx create-db, randb init, thenwrangler dev.POST /userscreated rows andGET /usersreturned them across repeated requests.tsc --noEmitandwrangler deploy --dry-runpass.wrangler d1 migrations create,prisma migrate diff --to-schema,wrangler d1 migrations apply --localandprisma generateas written, thenwrangler devreturned the inserted rows fromGET /. Local D1 only, sincewrangler d1 createand--remoteneed a Cloudflare account./api/usersreturned the seeded rows.Deploys to Cloudflare were not run.
One gotcha found while testing is now called out in the page: the Hono template ships a
pnpm-workspace.yaml, soorm initinstalls with pnpm unless the file is removed first.Disclosure: I work at Prisma. Happy to trim the Compute section or change anything else you'd like.