Skip to content

fix: date & timestamp format #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"build:server": "tsc -p tsconfig.server.json && cpy 'src/lib/sql/*.sql' bin/src/lib/sql",
"docs:export": "PG_META_EXPORT_DOCS=true ts-node-dev src/server/app.ts",
"start": "NODE_ENV=production node bin/src/server/app.js",
"dev": "run-s db:clean db:run && NODE_ENV=development ts-node-dev src/server/app.ts | pino-pretty --colorize",
"dev": "trap 'npm run db:clean' INT && run-s db:clean db:run && NODE_ENV=development ts-node-dev src/server/app.ts | pino-pretty --colorize",
"pkg": "run-s clean build:server && pkg --out-path bin .pkg.config.json",
"test": "run-s db:clean db:run test:run db:clean",
"db:clean": "cd test/db && docker-compose down",
"db:run": "cd test/db && docker-compose up --detach && sleep 5",
"test:run": "jest --runInBand"
"test:run": "jest --runInBand",
"test:update": "run-s db:clean db:run && jest --runInBand --updateSnapshot && run-s db:clean"
},
"engines": {
"node": ">=14 <15",
Expand All @@ -38,6 +39,7 @@
"pg-format": "^1.0.4",
"pgsql-parser": "^13.1.11",
"pino": "^7.6.3",
"postgres-array": "^3.0.1",
"prettier": "^2.4.1",
"prettier-plugin-sql": "^0.4.0",
"sql-formatter": "^4.0.2"
Expand Down
9 changes: 8 additions & 1 deletion src/lib/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { types, Pool, PoolConfig } from 'pg'
import { parse as parseArray } from 'postgres-array'
import { PostgresMetaResult } from './types'

types.setTypeParser(20, parseInt)
types.setTypeParser(types.builtins.INT8, parseInt)
types.setTypeParser(types.builtins.DATE, (x) => x)
types.setTypeParser(types.builtins.TIMESTAMP, (x) => x)
types.setTypeParser(types.builtins.TIMESTAMPTZ, (x) => x)
types.setTypeParser(1115, parseArray) // _timestamp
types.setTypeParser(1182, parseArray) // _date
types.setTypeParser(1185, parseArray) // _timestamptz

export const init: (config: PoolConfig) => {
query: (sql: string) => Promise<PostgresMetaResult<any>>
Expand Down
8 changes: 4 additions & 4 deletions test/lib/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ test('retrieve, create, update, delete', async () => {
"is_superuser": true,
"name": "r",
"password": "********",
"valid_until": 2020-01-01T00:00:00.000Z,
"valid_until": "2020-01-01 00:00:00+00",
},
"error": null,
}
Expand All @@ -467,7 +467,7 @@ test('retrieve, create, update, delete', async () => {
"is_superuser": true,
"name": "r",
"password": "********",
"valid_until": 2020-01-01T00:00:00.000Z,
"valid_until": "2020-01-01 00:00:00+00",
},
"error": null,
}
Expand Down Expand Up @@ -507,7 +507,7 @@ test('retrieve, create, update, delete', async () => {
"is_superuser": true,
"name": "rr",
"password": "********",
"valid_until": 2020-01-01T00:00:00.000Z,
"valid_until": "2020-01-01 00:00:00+00",
},
"error": null,
}
Expand All @@ -532,7 +532,7 @@ test('retrieve, create, update, delete', async () => {
"is_superuser": true,
"name": "rr",
"password": "********",
"valid_until": 2020-01-01T00:00:00.000Z,
"valid_until": "2020-01-01 00:00:00+00",
},
"error": null,
}
Expand Down