3.0.0 • Published 7 years ago

pg-custom-types v3.0.0

Weekly downloads
130
License
BSD-3-Clause
Repository
github
Last release
7 years ago

pg-custom-types Build Status

Use custom data types with node-postgres.

Installation

npm install pg-custom-types

Documentation

types(pg, connection, name, types, callback)

Fetches the OIDs for the given types.

Parameters

parametertypedescription
fetcherObjectThe query function of the form function (sql, callback)
keyStringA name for the given set of types, used to cache the results. It can be anything.
typesArrayThe array of data type names to fetch
callbackFunctionThe callback to call after the types are fetched

Callback is called with an object containing a lookup table.

{ 21842552: 'geometry',
  21842762: 'geography' }

Example

var types = require('pg-custom-types');

types(types.fetcher(pg, connection), 'postgis', ['geometry', 'geography'], (err, oids) {
  if (err) {
    throw err;
  }

  console.log(oids.geometry);
  console.log(oids.geography);

  pg.setTypeParser(oids.geometry, function (value) {
    // parse geometry type
  });
});