How to use the pg-types.getTypeParser function in pg-types

To help you get started, we’ve selected a few pg-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / pg-types / pg-types-tests.ts View on Github external
/// 
/// 
import * as types from "pg-types";

types.getTypeParser(1184, 'text');

types.setTypeParser(1184, (value) => value === null ? null : value);
types.setTypeParser(1186, 'text', (value) => value === null ? null : value);
types.setTypeParser(1186, 'binary', (value) => value.toISOString());
types.setTypeParser(1185, (value) => types.arrayParser.create(value, (x) => x).parse());

var TIMESTAMPTZ_OID = 1184
var TIMESTAMP_OID = 1114
var parseFn = function(val: any) {
   return val === null ? null : moment(val)
}
types.setTypeParser(TIMESTAMPTZ_OID, parseFn)
types.setTypeParser(TIMESTAMP_OID, parseFn)
github brianc / node-postgres / packages / pg / lib / defaults.js View on Github external
statement_timeout: false,

  // max milliseconds to wait for query to complete (client side)
  query_timeout: false,

  connect_timeout: 0,

  keepalives: 1,

  keepalives_idle: 0
}

var pgTypes = require('pg-types')
// save default parsers
var parseBigInteger = pgTypes.getTypeParser(20, 'text')
var parseBigIntegerArray = pgTypes.getTypeParser(1016, 'text')

// parse int8 so you can get your count values as actual numbers
module.exports.__defineSetter__('parseInt8', function (val) {
  pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger)
  pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray)
})
github brianc / node-postgres / packages / pg / lib / defaults.js View on Github external
// false=unlimited
  statement_timeout: false,

  // max milliseconds to wait for query to complete (client side)
  query_timeout: false,

  connect_timeout: 0,

  keepalives: 1,

  keepalives_idle: 0
}

var pgTypes = require('pg-types')
// save default parsers
var parseBigInteger = pgTypes.getTypeParser(20, 'text')
var parseBigIntegerArray = pgTypes.getTypeParser(1016, 'text')

// parse int8 so you can get your count values as actual numbers
module.exports.__defineSetter__('parseInt8', function (val) {
  pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger)
  pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray)
})
github DefinitelyTyped / DefinitelyTyped / types / pg-types / pg-types-tests.ts View on Github external
import * as types from "pg-types";

types.getTypeParser(1184, 'text');

types.setTypeParser(1184, (value) => value === null ? null : value);
types.setTypeParser(1186, 'text', (value) => value === null ? null : value);
types.setTypeParser(1186, 'binary', (value) => value.toISOString());
types.setTypeParser(1185, (value) => types.arrayParser.create(value, (x) => x).parse());

const TIMESTAMPTZ_OID = 1184;
const TIMESTAMP_OID = 1114;
types.setTypeParser(TIMESTAMPTZ_OID, parseInt);
types.setTypeParser(TIMESTAMP_OID, parseInt);
github C2FO / patio / lib / adapters / postgres.js View on Github external
PgTypes.setTypeParser(17, "text", byteaParser);

PgTypes.setTypeParser(20, 'text', function (val) {
    if (!getPatio().parseInt8) {
        return val;
    }

    var i = parseInt(val, 10);
    if (!isSafeInteger(i)) {
        throw new Error(format("The value '%s' cannot be represented by a javascript number.", val));
    }
    return i;
});

var timestampOrig = PgTypes.getTypeParser(1114, "text");
PgTypes.setTypeParser(1184, "text", function (val) {
    return getPatio().stringToDate(val.toString());
});

PgTypes.setTypeParser(1082, "text", function (val) {
    return getPatio().stringToDate(val.toString());
});

PgTypes.setTypeParser(1083, "text", function (val) {
    val = String(val);
    if (!val.match(/\.(\d{0,3})/)) {
        val += ".000";
    } else {
        val = val.replace(/\.(\d{0,3})$/, function (m, m1) {
            return "." + pad(m1, 3, "0", true);
        });
github brianc / node-postgres / packages / pg / lib / defaults.js View on Github external
module.exports.__defineSetter__('parseInt8', function (val) {
  pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger)
  pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray)
})
github brianc / node-postgres / packages / pg / lib / defaults.js View on Github external
module.exports.__defineSetter__('parseInt8', function (val) {
  pgTypes.setTypeParser(20, 'text', val ? pgTypes.getTypeParser(23, 'text') : parseBigInteger)
  pgTypes.setTypeParser(1016, 'text', val ? pgTypes.getTypeParser(1007, 'text') : parseBigIntegerArray)
})

pg-types

Query result type converters for node-postgres

MIT
Latest version published 10 months ago

Package Health Score

83 / 100
Full package analysis