fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO string (#6145)

* fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO string

* Fix linting issues
This commit is contained in:
OlegIvaniv
2023-05-04 17:25:54 +02:00
committed by GitHub
parent d381578926
commit 0eb4d9fc16
6 changed files with 19 additions and 5 deletions

View File

@@ -47,6 +47,15 @@ async function configurePostgres(
) {
const pgp = pgPromise();
if (typeof options.nodeVersion == 'number' && options.nodeVersion >= 2.1) {
// Always return dates as ISO strings
[pgp.pg.types.builtins.TIMESTAMP, pgp.pg.types.builtins.TIMESTAMPTZ].forEach((type) => {
pgp.pg.types.setTypeParser(type, (value: string) => {
return new Date(value).toISOString();
});
});
}
if (options.largeNumbersOutput === 'numbers') {
pgp.pg.types.setTypeParser(20, (value: string) => {
return parseInt(value, 10);