Comparing version 1.10.0 to 1.11.0
var array = require('postgres-array') | ||
var ap = require('ap') | ||
var arrayParser = require(__dirname + "/arrayParser.js"); | ||
var arrayParser = require('./arrayParser'); | ||
var parseDate = require('postgres-date'); | ||
@@ -156,2 +156,3 @@ var parseInterval = require('postgres-interval'); | ||
register(1007, parseIntegerArray); // _int4 | ||
register(1028, parseIntegerArray); // oid[] | ||
register(1016, parseBigIntegerArray); // _int8 | ||
@@ -158,0 +159,0 @@ register(1021, parseFloatArray); // _float4 |
{ | ||
"name": "pg-types", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "Query result type converters for node-postgres", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,3 +13,3 @@ # pg-types | ||
Generally what you'll want to do is override how a specific data-type is parsed and turned into a JavaScript type. By default the PostgreSQL backend server returns everything as strings. Every data type corresponds to a unique `OID` within the server, and these `OIDs` are sent back with the query response. So, you need to match a particluar `OID` to a function you'd like to use to take the raw text input and produce a valid JavaScript object as a result. | ||
Generally what you'll want to do is override how a specific data-type is parsed and turned into a JavaScript type. By default the PostgreSQL backend server returns everything as strings. Every data type corresponds to a unique `OID` within the server, and these `OIDs` are sent back with the query response. So, you need to match a particluar `OID` to a function you'd like to use to take the raw text input and produce a valid JavaScript object as a result. `null` values are never parsed. | ||
@@ -21,4 +21,3 @@ Let's do something I commonly like to do on projects: return 64-bit integers `(int8)` as JavaScript integers. Because JavaScript doesn't have support for 64-bit integers node-postgres cannot confidently parse `int8` data type results as numbers because if you have a _huge_ number it will overflow and the result you'd get back from node-postgres would not be the result in the datbase. That would be a __very bad thing__ so node-postgres just returns `int8` results as strings and leaves the parsing up to you. Let's say that you know you don't and wont ever have numbers greater than `int4` in your database, but you're tired of recieving results from the `COUNT(*)` function as strings (because that function returns `int8`). You would do this: | ||
types.setTypeParser(20, function(val) { | ||
//remember: all values returned from the server are either NULL or a string | ||
return val === null ? null : parseInt(val) | ||
return parseInt(val) | ||
}) | ||
@@ -34,4 +33,4 @@ ``` | ||
var moment = require('moment') | ||
var TIMESTAMPTZ_OID = 1114 | ||
var TIMESTAMP_OID = 1184 | ||
var TIMESTAMPTZ_OID = 1184 | ||
var TIMESTAMP_OID = 1114 | ||
var parseFn = function(val) { | ||
@@ -48,5 +47,11 @@ return val === null ? null : moment(val) | ||
```bash | ||
$ psql -c "select typname, oid, typarray from pg_type where typtype = 'b' order by oid" | ||
$ psql -c "select typname, oid, typarray from pg_type order by oid" | ||
``` | ||
If you want to find out the OID of a specific type: | ||
```bash | ||
$ psql -c "select typname, oid, typarray from pg_type where typname = 'daterange' order by oid" | ||
``` | ||
:smile: | ||
@@ -53,0 +58,0 @@ |
@@ -265,2 +265,12 @@ 'use strict' | ||
exports['array/oid'] = { | ||
format: 'text', | ||
id: 1028, | ||
tests: [ | ||
['{25864,25860}', function (t, value) { | ||
t.deepEqual(value, [25864, 25860]) | ||
}] | ||
] | ||
} | ||
exports['array/float4'] = { | ||
@@ -267,0 +277,0 @@ format: 'text', |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
25139
805
78
0