mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-20 20:21:18 -04:00
migrated to supabase postgres
This commit is contained in:
@@ -1,30 +1,18 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { PrismaNeon } from "@prisma/adapter-neon";
|
||||
import { Pool, neonConfig } from "@neondatabase/serverless";
|
||||
import ws from "ws";
|
||||
|
||||
// https://www.prisma.io/blog/serverless-database-drivers-KML1ehXORxZV#use-neon-with-neondatabaseserverless
|
||||
neonConfig.webSocketConstructor = ws;
|
||||
|
||||
// creating PrismaClient here prevents next.js from starting too many concurrent prisma instances and exhausting the
|
||||
// number of connection pools available (especially when hot reloading from `next dev`).
|
||||
// https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices
|
||||
|
||||
const prismaClientSingleton = () => {
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
ssl: true,
|
||||
});
|
||||
const adapter = new PrismaNeon(pool);
|
||||
return new PrismaClient({ adapter });
|
||||
return new PrismaClient();
|
||||
};
|
||||
|
||||
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
|
||||
}
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClientSingleton | undefined;
|
||||
};
|
||||
export const prisma = globalThis.prisma ?? prismaClientSingleton();
|
||||
|
||||
export const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
||||
if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;
|
||||
|
Reference in New Issue
Block a user