Skip to content

Instantly share code, notes, and snippets.

@darrylmorley
Created May 17, 2024 09:20
Show Gist options
  • Save darrylmorley/0e41298f43d023eaf40ced0be9c91536 to your computer and use it in GitHub Desktop.
Save darrylmorley/0e41298f43d023eaf40ced0be9c91536 to your computer and use it in GitHub Desktop.
Prisma TS Client

import { PrismaClient } from '@prisma/client'

const prismaClientSingleton = () => { return new PrismaClient() }

declare const globalThis: { prismaGlobal: ReturnType; } & typeof global;

const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()

export default prisma

if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma

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