Skip to content

Instantly share code, notes, and snippets.

@edanisko
Last active April 26, 2023 02:10
Show Gist options
  • Save edanisko/a335750580c608aa75a820a2465d6eb0 to your computer and use it in GitHub Desktop.
Save edanisko/a335750580c608aa75a820a2465d6eb0 to your computer and use it in GitHub Desktop.
SvelteKit - Prisma - /src/lib/server/prisma.ts
import { PrismaClient } from '@prisma/client'
// Avoid instantiating too many instances of Prisma in development
// https://www.prisma.io/docs/support/help-articles/nextjs-prisma-client-dev-practices#problem
let prisma: PrismaClient
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!global.prisma) {
global.prisma = new PrismaClient()
}
prisma = global.prisma
}
export { prisma }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment