Skip to content

9.3.0

Compare
Choose a tag to compare
@vitaly-t vitaly-t released this 05 Oct 09:34
· 395 commits to master since this release
3b4634e
  • Implemented #657, to support native BigInt type.
  • DEV dependencies updated
  • Documentation updates

BigInt Native Support

Now you can enable native BigInt support when running under Node.js v10.4.0 or later.

The following will make types BIGINT and BIGSERIAL arrive as BigInt type:

pgp.pg.types.setTypeParser(20, BigInt); // Type Id 20 = BIGINT | BIGSERIAL

And if you make use of arrays of BigInt, you can convert them with this:

// 1016 = Type Id for arrays of BigInt values
const parseBigIntArray = pgp.pg.types.getTypeParser(1016);
pgp.pg.types.setTypeParser(1016, a => parseBigIntArray(a).map(BigInt));

And the query-formatting engine now lets you use type BigInt for query values directly:

// 123n = BigInt('123')
await db.oneOrNone('SELECT * FROM table WHERE id = $1', [123n]);

// Example of the type changing into BigInt as it goes through the converter:
await db.one('SELECT $1::bigint as value', [123]); //=> {value: 123n}