Skip to content

Instantly share code, notes, and snippets.

@vedovelli
Created September 23, 2022 18:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vedovelli/7af0daeac50993e216709cef7ff37063 to your computer and use it in GitHub Desktop.
Save vedovelli/7af0daeac50993e216709cef7ff37063 to your computer and use it in GitHub Desktop.
Remix Prisma DB server
// @ts-nocheck
import { PrismaClient } from '@prisma/client';
let db: PrismaClient;
declare global {
let __db: PrismaClient | undefined;
}
// this is needed because in development we don't want to restart
// the server with every change, but we want to make sure we don't
// create a new connection to the DB with every change either.
if (process.env.NODE_ENV === 'production') {
db = new PrismaClient();
db.$connect();
} else {
if (!global.__db) {
global.__db = new PrismaClient();
global.__db.$connect();
}
db = global.__db;
}
export { db };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment