Go to file
2010-12-02 18:01:30 -06:00
lib nested query and streamlined api working 2010-12-02 17:47:54 -06:00
script script for debugging of text version of type output 2010-10-27 16:49:56 -05:00
test make 'assert.calls' short circuit on function call 2010-12-02 17:48:39 -06:00
.gitignore ignore project file 2010-10-23 17:08:51 -05:00
License added license file 2010-10-26 09:02:42 -05:00
package.json version bump 2010-11-21 23:30:43 -06:00
README.md updated docs to reflect new api 2010-12-02 18:01:30 -06:00

#node-postgres

Non-blocking (async) pure JavaScript PostgreSQL client for node.js written with love and TDD.

alpha version

Installation

npm install pg

Example

var pg = require('pg');

pg.connect("pg://user:password@host:port/database", function(err, client) {
  if(err) {
    //handle connection error
  }
  else {
    //queries are queued and executed in order
    client.query("CREATE TEMP TABLE user(name varchar(50), birthday timestamptz)");
    client.query("INSERT INTO user(name, birthday) VALUES('brianc', '1982-01-01T10:21:11')");
    
    //parameterized queries with transparent type coercion
    client.query("INSERT INTO user(name, birthday) VALUES($1, $2)", ['santa', new Date()]);
    
    //nested queries with callbacks
    client.query("SELECT * FROM user ORDER BY name", function(err, result) {
      if(err) {
        //handle query error
      }
      else {
        client.query("SELECT birthday FROM user WHERE name = $1", [result.rows[0].name], function(err, result) {
          //typed parameters and results
          assert.ok(result.rows[0].birthday.getYear() === 1982)
        })
      }
    })
  }
}

Philosophy

features

  • prepared statement support
    • parameters
    • query caching
  • type coercion
    • date <-> timestamptz
    • integer <-> integer, smallint, bigint
    • float <-> double, numeric
    • boolean <-> boolean
  • notification message support
  • tested like a Toyota ~1000 assertions executed on
    • ubuntu
      • node v0.2.2, v0.2.3, v0.2.4, v0.2.5, v0.3.0, v0.3.1
      • postgres 8.4.4
    • osx
      • node v0.2.2, v0.2.3, v0.2.4, v0.2.5, v0.3.0, v0.3.1
      • postgres v8.4.4, v9.0.1 installed both locally and on networked Windows 7

Contributing

clone the repo:

 git clone git://github.com/brianc/node-postgres
 cd node-postgres
 node test/run.js

And just like magic, you're ready to contribute! <3

More info please

Documentation

PLEASE check out the WIKI. MUCH more information there.

Working?

this page is running the worlds worst (but fully functional) PostgreSQL backed, Node.js powered website.

Why did you write this?

As soon as I saw node.js for the first time I knew I had found something lovely and simple and just what I always wanted!. So...I poked around for a while. I was excited. I still am!

I drew major inspiration from postgres-js.

I also drew some major inspirrado from node-mysql and liked what I saw there.

Plans for the future?

  • transparent prepared statement caching
  • connection pooling
  • more testings of error scenarios

License

node-postgres is licensed under the MIT license.