hill
PPrisma
•Created by hill on 5/5/2024 in #help-and-questions
Prisma ORM with Cloudflare D1/Next-on-pages
I'm transitioning my app from planetscale/prisma -> D1/Drizzle -> Cloudflare D1/prisma. Trying to set up a 'db.ts' folder which can be callable into different portions of the app to query the db. Anybody have experience setting this up? Doesn't help that there are only two examples in existence, both of which query D1 through a worker (rather than directly from the app).
This is my current code:
const adapter = new PrismaD1(
process.env.NODE_ENV === "development"
? getRequestContext().env.DB
: (process.env as any).DB
);
const db = new PrismaClient({ adapter })
and this is the old code, when using MySQL:
import { PrismaClient } from "@prisma/client"
declare global {
// eslint-disable-next-line no-var
var cachedPrisma: PrismaClient
}
let prisma: PrismaClient
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient()
} else {
if (!global.cachedPrisma) {
global.cachedPrisma = new PrismaClient()
}
prisma = global.cachedPrisma
}
export const db = prisma
Any assistance would be greatly appreciated.
3 replies