Skip to content

Scheduling infrastructure for absolutely everyone.

Adds prisma helper function whereAndSelect

Alex van Andel47d7634638ef
diff --git a/lib/prisma.ts b/lib/prisma.ts
index 4d3f847070e..b20a1b488b0 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<string, unknown>, pluckedAttributes: string[]) =>
+ modelQuery({
+ where: criteria,
+ select: pluckedAttributes.reduce(
+ (select: { [string]: boolean }, attr: string) => ({
+ ...select,
+ [attr]: true,
+ }),
+ {}
+ ),
+ });
+
+export { whereAndSelect };
+
+export default prisma;