2010-10-25 13:14:48 +08:00
#node-postgres
2010-11-21 04:41:37 +08:00
Non-blocking (async) pure JavaScript PostgreSQL client for node.js written
with love and TDD.
2010-10-25 13:14:48 +08:00
2010-12-15 09:37:09 +08:00
## Installation
2010-11-03 14:57:41 +08:00
npm install pg
2010-12-15 09:37:09 +08:00
## Example
2010-10-23 07:26:18 +08:00
2010-12-03 08:01:30 +08:00
var pg = require('pg');
2010-12-15 09:37:09 +08:00
var connectionString = "pg://user:password@host:port/database";
pg.connect(connectionString, function(err, client) {
2010-12-03 08:01:30 +08:00
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)
})
}
})
}
}
2011-01-11 06:31:01 +08:00
2010-12-15 09:37:09 +08:00
## Philosophy
2010-10-26 08:41:39 +08:00
2010-10-29 08:46:50 +08:00
* well tested
* no monkey patching
2010-11-21 04:41:37 +08:00
* no dependencies (...besides PostgreSQL)
2010-12-03 23:46:22 +08:00
* [in-depth documentation ](http://github.com/brianc/node-postgres/wiki ) (work in progress)
2010-11-05 12:20:16 +08:00
2010-12-15 09:37:09 +08:00
## features
2010-11-05 12:20:16 +08:00
- prepared statement support
- parameters
- query caching
- type coercion
- date < - > timestamptz
- integer < - > integer, smallint, bigint
- float < - > double, numeric
- boolean < - > boolean
- notification message support
2010-12-14 08:26:02 +08:00
- connection pooling
- mucho testing
2010-12-15 09:37:09 +08:00
~250 tests executed on
2010-11-05 12:20:16 +08:00
- ubuntu
2011-02-09 04:11:13 +08:00
- node v0.2.2, v0.2.3, v0.2.4, v0.2.5, v0.2.6, v0.3.0, v0.3.1, v0.3.2, v0.3.3, v0.3.4, v0.3.5, v0.3.6, v0.3.7, v0.3.8
2010-11-05 12:20:16 +08:00
- postgres 8.4.4
- osx
2011-02-09 04:11:13 +08:00
- node v0.2.2, v0.2.3, v0.2.4, v0.2.5, v0.2.6, v0.3.0, v0.3.1, v0.3.2, v0.3.3, v0.3.4, v0.3.5, v0.3.6, v0.3.7, v0.3.8
2010-11-21 04:41:37 +08:00
- postgres v8.4.4, v9.0.1 installed both locally and on networked Windows 7
2010-11-05 12:20:16 +08:00
2010-12-15 09:37:09 +08:00
## Contributing
2010-10-26 08:41:39 +08:00
2010-11-03 14:57:41 +08:00
clone the repo:
2010-10-26 08:41:39 +08:00
2010-10-29 08:46:50 +08:00
git clone git://github.com/brianc/node-postgres
cd node-postgres
2010-12-15 09:37:09 +08:00
make test
2010-10-26 14:58:42 +08:00
2010-10-29 08:46:50 +08:00
And just like magic, you're ready to contribute! < 3
2010-10-26 14:58:42 +08:00
2010-12-20 04:22:56 +08:00
### Contributors
Many thanks to the following:
* [creationix ](https://github.com/creationix )
* [felixge ](https://github.com/felixge )
2010-12-20 05:22:22 +08:00
* [pshc ](https://github.com/pshc )
2010-12-20 04:22:56 +08:00
* [pjornblomqvist ](https://github.com/bjornblomqvist )
* [JulianBirch ](https://github.com/JulianBirch )
2010-10-29 08:46:50 +08:00
## More info please
2010-10-26 14:58:42 +08:00
2010-12-20 05:25:05 +08:00
### [Documentation](node-postgres/wiki)
2010-10-29 11:27:50 +08:00
2010-12-20 05:25:05 +08:00
### __PLEASE__ check out the WIKI
2010-10-26 14:58:42 +08:00
2011-01-11 06:31:01 +08:00
## Help
If you need help or run into _any_ issues getting node-postgres to work on your system please report a bug or contact me directly.
2010-11-05 10:54:11 +08:00
### Working?
2010-11-05 10:55:03 +08:00
[this page ](http://www.explodemy.com ) is running the worlds worst (but fully functional) PostgreSQL backed, Node.js powered website.
2010-11-05 10:54:11 +08:00
2010-11-01 07:02:12 +08:00
### Why did you write this?
2010-10-26 08:41:39 +08:00
2010-12-15 09:37:09 +08:00
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!
2010-10-29 08:46:50 +08:00
2010-11-21 04:41:37 +08:00
I drew major inspiration from [postgres-js ](http://github.com/creationix/postgres-js ).
2010-10-26 08:41:39 +08:00
I also drew some major inspirrado from
[node-mysql ](http://github.com/felixge/node-mysql ) and liked what I
2010-11-21 04:41:37 +08:00
saw there.
### Plans for the future?
- transparent prepared statement caching
- more testings of error scenarios
2010-10-26 08:41:39 +08:00
2010-10-26 15:03:41 +08:00
## License
2010-12-03 08:03:32 +08:00
Copyright (c) 2010 Brian Carlson (brian.m.carlson@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.