Skip to content

docs(examples/prisma): update Prisma setup for Prisma ORM 8 - #922

Open
ankur-arch wants to merge 1 commit into
honojs:mainfrom
ankur-arch:docs/prisma-orm-8
Open

ankur-arch wants to merge 1 commit into
honojs:mainfrom
ankur-arch:docs/prisma-orm-8

Conversation

@ankur-arch

Copy link
Copy Markdown
Contributor

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

  • Prisma Postgres section: rewritten for Prisma ORM 8: npx prisma@latest orm init, the @prisma/orm-postgres package and the nodejs_compat flag. The example is a Hono middleware that creates one client per request and closes it with c.executionCtx.waitUntil, plus GET /users and POST /users routes. It follows the Prisma docs guide for Cloudflare Workers.
  • D1 section: stays on Prisma ORM 7 because Prisma ORM 8 has no D1 package yet, so the commands now pin prisma@7 and @prisma/client@7 (plain npx prisma installs 8 today). It drops the driverAdapters preview flag, switches to the prisma-client generator with runtime = "cloudflare", changes --to-schema-datamodel to --to-schema, fixes the client import path so it matches the generator output, and adds a wrangler.jsonc tab since the template now creates that file. It follows the Prisma Cloudflare D1 guide.
  • New section: a short pointer to running the same Hono app on Prisma Compute, linking the docs guide and the open-source example.
  • Resources: removed the dead caching link and updated the docs links.

How I tested

I followed the page step by step in fresh npm create hono@latest (cloudflare-workers) projects with Wrangler 4.151:

  • Prisma Postgres, Prisma ORM 8 (prisma 8.0.0-rc.24, @prisma/orm-postgres 8.0.0-rc.18): created a database with npx create-db, ran db init, then wrangler dev. POST /users created rows and GET /users returned them across repeated requests. tsc --noEmit and wrangler deploy --dry-run pass.
  • D1, Prisma ORM 7.10.1: ran wrangler d1 migrations create, prisma migrate diff --to-schema, wrangler d1 migrations apply --local and prisma generate as written, then wrangler dev returned the inserted rows from GET /. Local D1 only, since wrangler d1 create and --remote need a Cloudflare account.
  • Compute example: ran locally against a Prisma Postgres database and /api/users returned 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, so orm init installs 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.

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.
Comment thread examples/prisma.md
Here is an example of how you can use this function in your project:
app.use(async (c, next) => {
const db = postgres<Contract>({
contractJson,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 });

@yusukebe

Copy link
Copy Markdown
Member

Hey @ankur-arch

Thank you for the PR! Nice. I left a comment. Please check it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants