Giter VIP home page Giter VIP logo

node-pg-range's Introduction

node-pg-range

Range type support for node-postgres.

Usage

Install pg-range into your existing pg adapter:

var pg = require("pg");
require("pg-range").install(pg);

Then make a query that returns range objects!

client.query("SELECT range FROM table", function (result) {
  // result.range = {
  //   begin: Thu Mar 26 2014 17:57:02 GMT-0400 (EDT),
  //   end: Thu Mar 27 2014 17:57:02 GMT-0400 (EDT),
  //   bounds: '[)'
  // }
});

Or make a query that inserts range objects:

var Range = require("pg-range").Range;

client.query("INSERT INTO table VALUES ($1)", [Range(1, 3)]);

See the Postgres "Range Types" documentation for details.

Range objects

pg-range uses stRange.js, a JavaScript range library, to provide a Range class with useful methods, like contains and intersects. See the stRange.js API documentation.

Values of (PostgreSQL) type

  • int4range
  • int8range
  • numrange
  • tsrange
  • tstzrange
  • daterange

will be automatically parsed into instances of Range when the pg-range type adapter is installed.

Warning: When constructing range objects for use in queries, use the pg-range Range constructor as shown above, and not raw stRange.js Range objects. Raw stRange.js objects do not provide a toPostgres method, and will not properly serialize date ranges and empty ranges in queries!

node-pg-range's People

Contributors

benesch avatar ckiss avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.