diff --git a/lib/prisma.ts b/lib/prisma.ts index 4d3f847070..b20a1b488b 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -1,9 +1,9 @@ -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from "@prisma/client"; let prisma: PrismaClient; -const globalAny:any = global; +const globalAny: any = global; -if (process.env.NODE_ENV === 'production') { +if (process.env.NODE_ENV === "production") { prisma = new PrismaClient(); } else { if (!globalAny.prisma) { @@ -12,4 +12,18 @@ if (process.env.NODE_ENV === 'production') { prisma = globalAny.prisma; } -export default prisma; \ No newline at end of file +const whereAndSelect = (modelQuery, criteria: Record, pluckedAttributes: string[]) => + modelQuery({ + where: criteria, + select: pluckedAttributes.reduce( + (select: { [string]: boolean }, attr: string) => ({ + ...select, + [attr]: true, + }), + {} + ), + }); + +export { whereAndSelect }; + +export default prisma;