Skip to content

Commit

Permalink
Add the ability to pass custom log settings to Prisma (#8321)
Browse files Browse the repository at this point in the history
  • Loading branch information
MurzNN committed Feb 22, 2023
1 parent 1b264a5 commit 8e77298
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-ghosts-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Adds the ability to pass custom log level settings to Prisma Client
7 changes: 6 additions & 1 deletion packages/core/src/lib/createSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export function createSystem(config: KeystoneConfig) {
adminMeta,
getKeystone: (prismaModule: PrismaModule) => {
const prismaClient = new prismaModule.PrismaClient({
log: config.db.enableLogging ? ['query'] : undefined,
log:
config.db.enableLogging === true
? ['query']
: config.db.enableLogging === false
? undefined
: config.db.enableLogging,
datasources: { [config.db.provider]: { url: config.db.url } },
});

Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,21 @@ export type { ListSchemaConfig, ListConfig, BaseFields, MaybeSessionFunction, Ma

// config.db

// Copy of the Prisma's LogLevel types from `src/runtime/getLogLevel.ts`,
// because they are not exported by Prisma.
type PrismaLogLevel = 'info' | 'query' | 'warn' | 'error';
type PrismaLogDefinition = {
level: PrismaLogLevel;
emit: 'stdout' | 'event';
};

export type DatabaseConfig<TypeInfo extends BaseKeystoneTypeInfo> = {
url: string;
shadowDatabaseUrl?: string;
onConnect?: (args: KeystoneContext<TypeInfo>) => Promise<void>;
/** @deprecated */
useMigrations?: boolean;
enableLogging?: boolean;
enableLogging?: boolean | PrismaLogLevel | Array<PrismaLogLevel | PrismaLogDefinition>;
idField?: IdFieldConfig;
provider: DatabaseProvider;

Expand Down

0 comments on commit 8e77298

Please sign in to comment.