prisma-query-log
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -1,8 +0,1 @@ | ||
declare type PrismaQueryEvent = { | ||
timestamp: Date; | ||
query: string; | ||
params: string; | ||
duration: number; | ||
target: string; | ||
}; | ||
declare const defaultOptions: { | ||
@@ -36,9 +29,27 @@ /** | ||
*/ | ||
formatterOptions: Partial<{ | ||
language: string | undefined; | ||
indent: string; | ||
reservedWordCase: "upper" | "lower" | null; | ||
linesBetweenQueries: number | "preserve"; | ||
}>; | ||
/** | ||
* Query language, default is Standard SQL | ||
*/ | ||
language: "sql" | "n1ql" | "db2" | "pl/sql" | undefined; | ||
/** | ||
* Characters used for indentation | ||
*/ | ||
indent: string; | ||
/** | ||
* How to change the case of reserved words | ||
*/ | ||
reservedWordCase: "upper" | "lower" | null; | ||
/** | ||
* How many line breaks between queries | ||
*/ | ||
linesBetweenQueries: number | "preserve"; | ||
}; | ||
declare type PrismaQueryEvent = { | ||
timestamp: Date; | ||
query: string; | ||
params: string; | ||
duration: number; | ||
target: string; | ||
}; | ||
declare type CreatePrismaQueryEventHandlerArgs = typeof defaultOptions; | ||
@@ -45,0 +56,0 @@ declare function createPrismaQueryEventHandler(args?: Partial<CreatePrismaQueryEventHandlerArgs>): (event: PrismaQueryEvent) => void; |
29
index.js
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __assign = Object.assign; | ||
// src/index.ts | ||
var defaultFormatterOptions = { | ||
language: void 0, | ||
indent: " ", | ||
reservedWordCase: null, | ||
linesBetweenQueries: 1 | ||
}; | ||
// src/options.ts | ||
var defaultOptions = { | ||
@@ -16,17 +10,20 @@ logger: true, | ||
format: false, | ||
formatterOptions: defaultFormatterOptions | ||
language: void 0, | ||
indent: " ", | ||
reservedWordCase: null, | ||
linesBetweenQueries: 1 | ||
}; | ||
// src/index.ts | ||
var formatter; | ||
function createPrismaQueryEventHandler(args = {}) { | ||
var _a, _b, _c; | ||
const customFormatterOptions = (_a = args.formatterOptions) != null ? _a : {}; | ||
var _a; | ||
const options = __assign(__assign({}, defaultOptions), args); | ||
const logger = options.logger === true ? console.log : (_b = options.logger) != null ? _b : false; | ||
if (!logger) { | ||
const logger = options.logger === true ? console.log : options.logger; | ||
if (typeof logger !== "function") { | ||
return Function.prototype; | ||
} | ||
const {unescape, format} = options; | ||
const formatterOptions = __assign(__assign({}, options.formatterOptions), customFormatterOptions); | ||
const colorQuery = format ? false : options.colorQuery; | ||
const colorParameter = (_c = options.colorParameter) != null ? _c : colorQuery; | ||
const colorParameter = (_a = options.colorParameter) != null ? _a : colorQuery; | ||
return function prismaQueryLog(event) { | ||
@@ -39,3 +36,3 @@ const eventParams = event.params.replace(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ UTC/g, (date) => `"${date}"`); | ||
} | ||
query = query.replace(/\?/g, (s, index, string) => { | ||
query = query.replace(/\?/g, (_, index, string) => { | ||
let parameter = JSON.stringify(params.shift()); | ||
@@ -52,3 +49,3 @@ const previousChar = string.charAt(index - 1); | ||
} | ||
query = formatter.format(query, formatterOptions).trim(); | ||
query = formatter.format(query, options).trim(); | ||
} | ||
@@ -55,0 +52,0 @@ if (colorQuery && colorParameter) { |
{ | ||
"name": "prisma-query-log", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Log prisma query event", |
@@ -63,16 +63,30 @@ # prisma-query-log | ||
/** | ||
* Format SQL query. | ||
* Format SQL query, | ||
* colorQuery/colorParameter will be ignored. | ||
*/ | ||
format: false, | ||
/** | ||
* Poor Man's T-SQL Formatter options | ||
* https://github.com/TaoK/poor-mans-t-sql-formatter-npm-package#usage | ||
* Formatter options | ||
* https://github.com/mtxr/vscode-sqltools/tree/master/packages/formatter#options | ||
*/ | ||
formatterOptions: { | ||
maxLineWidth: 80, | ||
indent: ' ', | ||
expandCommaLists: false, | ||
expandInLists: false, | ||
}, | ||
/** | ||
* Query language, default is Standard SQL | ||
*/ | ||
language: undefined as 'sql' | 'n1ql' | 'db2' | 'pl/sql' | undefined, | ||
/** | ||
* Characters used for indentation | ||
*/ | ||
indent: ' ', | ||
/** | ||
* How to change the case of reserved words | ||
*/ | ||
// eslint-disable-next-line unicorn/no-null | ||
reservedWordCase: null as 'upper' | 'lower' | null, | ||
/** | ||
* How many line breaks between queries | ||
*/ | ||
linesBetweenQueries: 1 as number | 'preserve', | ||
}; | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10075
129
92