rallly/packages/database/index.ts
2024-10-13 17:24:24 +01:00

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;