Skip to content

Commit 2cf9167

Browse files
committed
fix: return date, timestamp, timestamptz as string
1 parent c8d0279 commit 2cf9167

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

Diff for: package-lock.json

+23-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"test": "run-s db:clean db:run test:run db:clean",
2727
"db:clean": "cd test/db && docker-compose down",
2828
"db:run": "cd test/db && docker-compose up --detach && sleep 5",
29-
"test:run": "jest --runInBand"
29+
"test:run": "jest --runInBand",
30+
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean"
3031
},
3132
"engines": {
3233
"node": ">=14 <15",
@@ -38,6 +39,7 @@
3839
"pg-format": "^1.0.4",
3940
"pgsql-parser": "^13.1.11",
4041
"pino": "^7.6.3",
42+
"postgres-array": "^3.0.1",
4143
"prettier": "^2.4.1",
4244
"prettier-plugin-sql": "^0.4.0",
4345
"sql-formatter": "^4.0.2"

Diff for: src/lib/db.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { types, Pool, PoolConfig } from 'pg'
2+
import { parse as parseArray } from 'postgres-array'
23
import { PostgresMetaResult } from './types'
34

4-
types.setTypeParser(20, parseInt)
5+
types.setTypeParser(types.builtins.INT8, parseInt)
6+
types.setTypeParser(types.builtins.DATE, (x) => x)
7+
types.setTypeParser(types.builtins.TIMESTAMP, (x) => x)
8+
types.setTypeParser(types.builtins.TIMESTAMPTZ, (x) => x)
9+
types.setTypeParser(1115, parseArray) // _timestamp
10+
types.setTypeParser(1182, parseArray) // _date
11+
types.setTypeParser(1185, parseArray) // _timestamptz
512

613
export const init: (config: PoolConfig) => {
714
query: (sql: string) => Promise<PostgresMetaResult<any>>

Diff for: test/lib/roles.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ test('retrieve, create, update, delete', async () => {
442442
"is_superuser": true,
443443
"name": "r",
444444
"password": "********",
445-
"valid_until": 2020-01-01T00:00:00.000Z,
445+
"valid_until": "2020-01-01 00:00:00+00",
446446
},
447447
"error": null,
448448
}
@@ -467,7 +467,7 @@ test('retrieve, create, update, delete', async () => {
467467
"is_superuser": true,
468468
"name": "r",
469469
"password": "********",
470-
"valid_until": 2020-01-01T00:00:00.000Z,
470+
"valid_until": "2020-01-01 00:00:00+00",
471471
},
472472
"error": null,
473473
}
@@ -507,7 +507,7 @@ test('retrieve, create, update, delete', async () => {
507507
"is_superuser": true,
508508
"name": "rr",
509509
"password": "********",
510-
"valid_until": 2020-01-01T00:00:00.000Z,
510+
"valid_until": "2020-01-01 00:00:00+00",
511511
},
512512
"error": null,
513513
}
@@ -532,7 +532,7 @@ test('retrieve, create, update, delete', async () => {
532532
"is_superuser": true,
533533
"name": "rr",
534534
"password": "********",
535-
"valid_until": 2020-01-01T00:00:00.000Z,
535+
"valid_until": "2020-01-01 00:00:00+00",
536536
},
537537
"error": null,
538538
}

0 commit comments

Comments
 (0)