-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Edited by @bombillazo
Is your feature request related to a problem? Please describe.
By default, data returned by the database driver is serialized in a string.
While some database types can be automatically decoded into a common JS type, developers may need more control over the data parsing to convert from the DB types to the TS/JS types. One example can be parsing date or timestamptz data from PG to a Date lib object like Luxon or DayJs instead of the standard JS Date object. Another example could be parsing money data from PG to a lib like currency.js.
Returning the values as strings puts the burden on the developer to handle the deserialization of the different data types in their application. This affects the development experience and opens up the possibility for users to develop inefficient implementations.
Describe the solution you'd like
Add an option to the ClientOptions to add a custom function for a specific Oid:
import { DateTime } from "luxon";
import { Client, Oid, ... } from "postgres";
const client = new Client({
database: 'postgres',
...,
parsers: {
[Oid.date]: (value: string) => {
// custom parsing logic
return DateTime.fromISO(value)
},
});Dev can now have complete control over handling or overriding the type conversion provided by postgres.
Describe alternatives you've considered
Directly changing the package source code in my application to override the behavior
Additional context
Related Issues : #128