diff --git a/package.json b/package.json index 62f774a..dab020f 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "homepage": "https://github.com/BemiHQ/bemi-prisma#readme", "dependencies": { "@prisma/driver-adapter-utils": "^5.9.1", - "@prisma/internals": "^5.9.1", "commander": "^11.1.0", + "kleur": "^4.1.5", "pg": "^8.11.5", "postgres-array": "^3.0.2" }, diff --git a/src/index.ts b/src/index.ts index e6e1a11..51bf996 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { Request, Response, NextFunction } from "express"; import { PrismaPg } from './pg-adapter'; import { isContextComment, isWriteQuery, contextToSqlComment } from './pg-utils' -import { log } from './logger' +import { logger } from './logger' const WRITE_OPERATIONS = ["create", "update", "upsert", "delete", "createMany", "updateMany", "deleteMany"] const EXECUTE_OPERATIONS = ["$executeRaw", "$executeRawUnsafe"] @@ -37,7 +37,7 @@ export const withPgAdapter = (originalPrisma: PrismaClientType const context = ASYNC_LOCAL_STORAGE.getStore() if (!context || context.constructor !== Object) return query(args) - log('EXTENSION:', operation, args) + logger.debug('EXTENSION:', operation, args) // The PG adapter will remove the transaction and add the comment // to the query directly to be executed as a single SQL statement diff --git a/src/logger.ts b/src/logger.ts index e4ce64e..b0a06b5 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,6 +1,18 @@ -export const log = (...args: any[]) => { - if (process.env.BEMI_DEBUG === 'true') { - const [message, ...rest] = args - console.log(`>>[Bemi] ${message}`, ...rest); - } +import { blue } from 'kleur/colors' + +export const logger = { + tags: { + info: blue('prisma:query'), + }, + + log: (...args: any[]) => { + console.log(...args); + }, + + debug: (...args: any[]) => { + if (process.env.BEMI_DEBUG === 'true') { + const [message, ...rest] = args + console.log(`>>[Bemi] ${message}`, ...rest); + } + }, } diff --git a/src/pg-adapter.ts b/src/pg-adapter.ts index 990fc5a..4361c10 100644 --- a/src/pg-adapter.ts +++ b/src/pg-adapter.ts @@ -19,8 +19,7 @@ import { fieldToColumnType, fixArrayBufferValues, UnsupportedNativeDataType } fr const debug = Debug('prisma:driver-adapter:pg') // PATCH: Import additional things -import { logger } from '@prisma/internals' -import { log } from './logger' +import { logger } from './logger' import { StdClient, TransactionClient, @@ -134,7 +133,7 @@ class PgQueryable implements Quer // Modify the execution if (this.client.logQueries && !catchingUp) { - log('QUERY:', sql, previousQueries ? previousQueries.length : '') + logger.debug('QUERY:', sql, previousQueries ? previousQueries.length : '') } // Transaction queries