Skip to content

Commit

Permalink
[debug] onPrisma type debug
Browse files Browse the repository at this point in the history
  • Loading branch information
leomerida15 committed Feb 5, 2024
1 parent 29bac44 commit a339a85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.7",
"version": "1.1.8",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
14 changes: 6 additions & 8 deletions src/prisma/onPrisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ export const onPrisma = <PrismaClient>(
PrismaClientNative: new () => PrismaClient,
options?: onPrismaParamsOptios,
) => {
if ((global as Global<PrismaClient>).prisma) {
return { prisma: (global as Global<PrismaClient>).prisma };
}

if (options?.whereGlobal) {
const prisma = prismaAddGlobalWhere(
new PrismaClientNative(),
options?.whereGlobal,
);

(global as Global<PrismaClient>).prisma = prisma;
if (prisma) {
(global as unknown as Global<PrismaClient>).prisma = prisma;

return { prisma: (global as Global<PrismaClient>).prisma };
return { prisma: (global as unknown as Global<PrismaClient>).prisma };
}
}

(global as Global<PrismaClient>).prisma = new PrismaClientNative();
(global as unknown as Global<PrismaClient>).prisma = new PrismaClientNative();

return { prisma: (global as Global<PrismaClient>).prisma };
return { prisma: (global as unknown as Global<PrismaClient>).prisma };
};
6 changes: 5 additions & 1 deletion src/prisma/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ export interface PrismaClientCustom {
}

export interface Global<PrismaClient> {
prisma?: PrismaClient;
prisma: PrismaClient;
}

export interface onPrismaParamsOptios {
whereGlobal: object;
}

export interface onPrismaReturn<PrismaClient> {
prisma: PrismaClient;
}

0 comments on commit a339a85

Please sign in to comment.