mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-30 02:36:30 +02:00
32 lines
905 B
TypeScript
32 lines
905 B
TypeScript
import { PrismaClient } from "@prisma/client";
|
|
|
|
export type * from "@prisma/client";
|
|
|
|
const prismaClientSingleton = () => {
|
|
return new PrismaClient().$extends({
|
|
query: {
|
|
poll: {
|
|
findMany: ({ args, query }) => {
|
|
if (!args.where?.deleted) {
|
|
args.where = { ...args.where, deleted: false };
|
|
}
|
|
|
|
return query(args);
|
|
},
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
export type ExtendedPrismaClient = ReturnType<typeof prismaClientSingleton>;
|
|
|
|
// biome-ignore lint/suspicious/noShadowRestrictedNames: https://www.prisma.io/docs/orm/more/help-and-troubleshooting/help-articles/nextjs-prisma-client-dev-practices
|
|
declare const globalThis: {
|
|
prismaGlobal: ExtendedPrismaClient;
|
|
} & typeof global;
|
|
|
|
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();
|
|
|
|
export { prisma };
|
|
|
|
if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
|