purescript-pg/src/Data.Postgres.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-03-27 20:26:40 +00:00
import Pg from 'pg'
import Range from 'postgres-range'
2024-03-27 02:59:28 +00:00
export const null_ = null
export const modifyPgTypes = () => {
const oid = {
'text[]': 1009,
json: 114,
jsonb: 3802,
'json[]': 199,
'jsonb[]': 3807,
timestamp: 1114,
timestamptz: 1184,
'timestamp[]': 1115,
'timestamptz[]': 1185,
tsrange: 3908,
tstzrange: 3910,
}
// @ts-ignore
const asString = a => a
2024-03-27 17:20:33 +00:00
const asStringArray = Pg.types.getTypeParser(oid['text[]'])
2024-03-27 02:59:28 +00:00
const asStringRange = Range.parse
2024-03-27 17:20:33 +00:00
Pg.types.setTypeParser(oid['json'], asString)
Pg.types.setTypeParser(oid['jsonb'], asString)
Pg.types.setTypeParser(oid['json[]'], asStringArray)
Pg.types.setTypeParser(oid['jsonb[]'], asStringArray)
2024-03-27 02:59:28 +00:00
2024-03-27 17:20:33 +00:00
Pg.types.setTypeParser(oid['timestamp'], asString)
Pg.types.setTypeParser(oid['timestamptz'], asString)
Pg.types.setTypeParser(oid['timestamp[]'], asStringArray)
Pg.types.setTypeParser(oid['timestamptz[]'], asStringArray)
Pg.types.setTypeParser(oid['tsrange'], asStringRange)
Pg.types.setTypeParser(oid['tstzrange'], asStringRange)
2024-03-27 02:59:28 +00:00
}