Registry / database / prisma-query-formatter

prisma-query-formatter

JSON →
library1.0.1jsnpmunverified

prisma-query-formatter (v1.0.1) formats Prisma query logs by substituting placeholders with actual values, supporting all databases including PostgreSQL. It handles non-standard JSON param serialization from Prisma's internal Rust engine, providing clean console output for debugging. Zero dependencies, ships TypeScript types. Released actively with minor patches. Unlike simple string replace, it correctly parses Prisma's param format and offers options like throwOnError and custom param transformers.

npm install prisma-query-formatter
INSTALL
IMPORT
SIG · PRISMA-QUERY-FORMA
P
prisma-query-formatter
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatQuery
import { formatQuery } from 'prisma-query-formatter';
const formatQuery = require('prisma-query-formatter');
ESM recommended. CommonJS also supported.
escapeWhitespace
import { escapeWhitespace } from 'prisma-query-formatter';
import escapeWhitespace from 'prisma-query-formatter/escapeWhitespace';
Named export, not default. Also exported as part of the main module.
FormatQueryOptions
import type { FormatQueryOptions } from 'prisma-query-formatter';
import { FormatQueryOptions } from 'prisma-query-formatter';
Type import, only needed for TypeScript.

Shows how to set up Prisma event-based query logging with formatQuery to substitute params and print formatted queries to console.

import { PrismaClient } from '@prisma/client'; import { formatQuery } from 'prisma-query-formatter'; const prisma = new PrismaClient({ log: [ { emit: 'event', level: 'query' }, ], }); prisma.$on('query', (e) => { console.log(formatQuery(e.query, e.params)); }); async function main() { await prisma.user.findUnique({ select: { id: true }, where: { email: 'john@example.com' }, }); } main() .catch(console.error) .finally(() => prisma.$disconnect());
Debug
Known issues
breakingThe library now throws an error if the number of placeholders in query doesn't match params count (when throwOnError is true).
fix
Set throwOnError: false (default) or wrap in try/catch as shown in docs.
affects: >=1.0.0
gotchaParameters are irreversibly converted by Prisma for some types (e.g., blobs). Formatted output is for logging only, not for execution.
fix
Do not use the formatted query to execute against database.
affects: *
gotchaIf params contain whitespace characters like \n, they are not escaped by default; the query log may become multiline.
fix
Use escapeWhitespace as paramTransformer to escape whitespace.
affects: <=1.0.1
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'replace')
Passing undefined or null as params to formatQuery.
fix
Ensure e.params is a string; default to empty string if undefined: formatQuery(e.query, e.params ?? '')
TypeError: e.query.replace is not a function
Passing an object instead of a string as first argument.
fix
Check that e.query is the query string from Prisma event.
The number of placeholders (2) does not match number of params (3).
Mismatch between placeholders in query and params array length (only thrown if throwOnError: true).
fix
Set throwOnError: false or fix query/params mismatch.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
prisma-query-formatter — npm install prisma-query-formatter · libregistry