brianc / node-pg-types

Type parsing for node-postgres
267 stars 54 forks source link

Parse array of BigInt #111

Closed s888 closed 4 years ago

s888 commented 4 years ago

Hi, I have a column of type bigint[] But in response, it is converted to an array of string.

How do I parse it? This works when the column is of type bigint

import { types } from "pg"
types.setTypeParser(20, BigInt); 

Tried this but it gives an error.

import { Client, types } from "pg"
types.setTypeParser(1016, str => types.arrayParser(str,BigInt));
bendrucker commented 4 years ago

What error?

sehrope commented 4 years ago

Must be that arrayParser(...) is no longer re-exported: https://github.com/brianc/node-pg-types/commit/09ea6256a4addca199d45db850e59ce50e330d34#diff-168726dbe96b3ce427e7fedce31bb0bcL3

Try something like this to use it directly from the postgres-array package:

const { types } = require('pg')
const pgArray = require('postgres-array')
types.setTypeParser(1016, text => pgArray.parse(text, BigInt))
bendrucker commented 4 years ago

Good catch, thanks!