Skip to content

Commit

Permalink
docs(cbjs): explicit mention of json-bigint as custom query row parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusTheHun committed Sep 24, 2024
1 parent 0d73834 commit 6c92eec
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions docs/src/guide/services/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ console.log(typeof queryCas); // 'number'
console.log(queryCas > Number.MAX_SAFE_INTEGER); // true
```

So you may want to pass a custom parser :
So you may want to pass a custom parser, such as `json-bigint` :

```ts
import JSONBigint from 'json-bigint';
Expand All @@ -73,18 +73,3 @@ const cluster = connect('...', {
queryResultParser: customParser
})
```

::: tip
Starting with Node.js v21, you can use the following reviver to parse `cas` :

```ts
function bigIntReviver(key: string, value: unknown, context?: { source: string }) {
if (!context) throw new Error('Missing `context` in JSON.parse reviver function.');

if (typeof value === 'number' && value > Number.MAX_SAFE_INTEGER) {
return BigInt(context.source);
}
return value;
};
```
:::

0 comments on commit 6c92eec

Please sign in to comment.