forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Remove whereAndSelect and fix typescript of main PrismaClient …
…adapter (calcom#966)
- Loading branch information
Showing
2 changed files
with
10 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,18 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
let prisma: PrismaClient; | ||
const globalAny: any = global; | ||
|
||
if (process.env.NODE_ENV === "production") { | ||
prisma = new PrismaClient(); | ||
} else { | ||
if (!globalAny.prisma) { | ||
globalAny.prisma = new PrismaClient({ | ||
log: ["query", "error", "warn"], | ||
}); | ||
} | ||
prisma = globalAny.prisma; | ||
declare global { | ||
// eslint-disable-next-line no-var | ||
var prisma: PrismaClient | undefined; | ||
} | ||
|
||
const pluck = (select: Record<string, boolean>, attr: string) => { | ||
const parts = attr.split("."); | ||
const alwaysAttr = parts[0]; | ||
const pluckedValue = | ||
parts.length > 1 | ||
? { | ||
select: pluck(select[alwaysAttr] ? select[alwaysAttr].select : {}, parts.slice(1).join(".")), | ||
} | ||
: true; | ||
return { | ||
...select, | ||
[alwaysAttr]: pluckedValue, | ||
}; | ||
}; | ||
|
||
/** | ||
* @deprecated | ||
* This function will always return `any` type, | ||
* See https://github.com/calendso/calendso/pull/460 for alternative approach | ||
*/ | ||
const whereAndSelect = (modelQuery, criteria: Record<string, unknown>, pluckedAttributes: string[]) => | ||
modelQuery({ | ||
where: criteria, | ||
select: pluckedAttributes.reduce(pluck, {}), | ||
export const prisma = | ||
globalThis.prisma || | ||
new PrismaClient({ | ||
log: ["query", "error", "warn"], | ||
}); | ||
|
||
export { whereAndSelect }; | ||
if (process.env.NODE_ENV !== "production") { | ||
globalThis.prisma = prisma; | ||
} | ||
|
||
export default prisma; |
This file was deleted.
Oops, something went wrong.