drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Option to pass reviver to JSON.parse

Open
#2,858 2 comments 0 reactions 0 assignees View on GitHub
db/postgres improvement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

I'm trying to create a custom type to revive some of my JSON. But when the value of the jsonb column gets to the fromDriver hook, it is already an object, meaning the JSON.parse is happening someplace else.
```
export const jsonb = (name: string) =>
customType({
dataType() {
return "jsonb"
},
toDriver(value) {
return JSON.stringify(value)
},
fromDriver(value) {
console.log(typeof value)
return value
},
})(name)
```

While I can still solve my specific problem doing the revive work here, It would be nice to have an option to pass the JSON.parse implementation we desire. Something like:

```
const client = drizzle(
connection,
debug ? { logger: new DefaultLogger({ writer: new ConsoleLogWriter() }) } : undefined,
stringifyJson: undefined,
parseJson: (value) => {
return JSON.parse(value)
},
)
```

Thanks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.