Adds prisma helper function whereAndSelect
parent
90d6f8faee
commit
47d7634638
|
@ -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;
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue