Skip to content

Commit

Permalink
Readme badges, add example for escapeParams
Browse files Browse the repository at this point in the history
  • Loading branch information
s1owjke committed May 19, 2024
1 parent 0c196b1 commit 98ec637
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Prisma Query Formatter

This small zero-dependency utility correctly formats Prisma queries by substituting placeholders with their corresponding values.
[![Published on npm](https://img.shields.io/npm/v/prisma-query-formatter?color=brightgreen)](https://www.npmjs.com/package/prisma-query-formatter) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

This small zero-dependency utility correctly formats Prisma queries by substituting placeholders with their corresponding values, support all databases including PostgreSQL.

Internally, Prisma uses its [own](https://github.com/prisma/prisma-engines/blob/5.13.0/quaint/src/ast/values.rs#L547) Rust implementation for stringifying params, so you couldn't just use `JSON.parse` to convert them back to an array (sometimes it's not valid json, like double quotes are not escaped in strings).

Expand Down Expand Up @@ -67,3 +69,9 @@ prisma.$on("query", (e) => {
console.log(formatQuery(e.query, e.params, { escapeParams: true }));
});
```

And then, they will be displayed like this:

```text
SELECT `Post`.`id` FROM `Post` WHERE `Post`.`title` = "first\nsecond"
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prisma-query-formatter",
"version": "0.1.1",
"version": "0.1.2",
"description": "Small utility for Prisma query formatting and param substitution",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 98ec637

Please sign in to comment.