Skip to content

Commit 6da2239

Browse files
author
anton
committed
Merge branch 'master' of https://github.com/brianc/node-postgres
Conflicts: lib/connection.js lib/query.js
2 parents 486a2d0 + 01c7d16 commit 6da2239

File tree

10 files changed

+76
-336
lines changed

10 files changed

+76
-336
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ node-command := xargs -n 1 -I file node file $(params)
99
.PHONY : test test-connection test-integration bench test-native build/default/binding.node
1010

1111
help:
12-
echo "make test-all connectionString=pg://<your connection string>"
12+
@echo "make prepare-test-db [connectionString=pg://<your connection string>]"
13+
@echo "make test-all [connectionString=pg://<your connection string>]"
1314

1415
test: test-unit
1516

@@ -25,20 +26,27 @@ test-unit:
2526
@find test/unit -name "*-tests.js" | $(node-command)
2627

2728
test-connection:
29+
@echo "***Testing connection***"
2830
@node script/test-connection.js $(params)
2931

3032
test-connection-binary:
33+
@echo "***Testing binary connection***"
3134
@node script/test-connection.js $(params) binary
3235

3336
test-native: build/default/binding.node
3437
@echo "***Testing native bindings***"
3538
@find test/native -name "*-tests.js" | $(node-command)
3639
@find test/integration -name "*-tests.js" | $(node-command) native
3740

38-
test-integration: test-connection
41+
test-integration: test-connection
3942
@echo "***Testing Pure Javascript***"
4043
@find test/integration -name "*-tests.js" | $(node-command)
4144

4245
test-binary: test-connection-binary
4346
@echo "***Testing Pure Javascript (binary)***"
4447
@find test/integration -name "*-tests.js" | $(node-command) binary
48+
49+
prepare-test-db:
50+
@echo "***Preparing the database for tests***"
51+
@find script/create-test-tables.js | $(node-command)
52+

README.md

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
[![Build Status](https://secure.travis-ci.org/brianc/node-postgres.png)](http://travis-ci.org/brianc/node-postgres)
44

5-
Non-blocking PostgreSQL client for node.js. Pure JavaScript and native libpq bindings. Active development, well tested, and production use.
5+
PostgreSQL client for node.js. Pure JavaScript and native libpq bindings.
66

77
## Installation
88

99
npm install pg
1010

1111
## Examples
1212

13-
### Simple, using built-in client pool
13+
### Callbacks
1414

1515
```javascript
1616
var pg = require('pg');
@@ -19,17 +19,18 @@ var pg = require('pg');
1919

2020
var conString = "tcp://postgres:1234@localhost/postgres";
2121

22-
//error handling omitted
23-
pg.connect(conString, function(err, client) {
24-
client.query("SELECT NOW() as when", function(err, result) {
25-
console.log("Row count: %d",result.rows.length); // 1
26-
console.log("Current year: %d", result.rows[0].when.getFullYear());
27-
pg.end(); //terminate the client pool, disconnecting all clients
28-
});
22+
//note: error handling omitted
23+
var client = new pg.Client(conString);
24+
client.connect(function(err) {
25+
client.query('SELECT NOW() AS "theTime"', function(err, result) {
26+
console.log(result.rows[0].theTime);
27+
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
28+
})
2929
});
30+
3031
```
3132

32-
### Evented api
33+
### Events
3334

3435
```javascript
3536
var pg = require('pg'); //native libpq bindings = `var pg = require('pg').native`
@@ -40,22 +41,7 @@ client.connect();
4041

4142
//queries are queued and executed one after another once the connection becomes available
4243
client.query("CREATE TEMP TABLE beatles(name varchar(10), height integer, birthday timestamptz)");
43-
client.query("INSERT INTO beatles(name, height, birthday) values($1, $2, $3)", ['Ringo', 67, new Date(1945, 11, 2)]);
4444
client.query("INSERT INTO beatles(name, height, birthday) values($1, $2, $3)", ['John', 68, new Date(1944, 10, 13)]);
45-
46-
//queries can be executed either via text/parameter values passed as individual arguments
47-
//or by passing an options object containing text, (optional) parameter values, and (optional) query name
48-
client.query({
49-
name: 'insert beatle',
50-
text: "INSERT INTO beatles(name, height, birthday) values($1, $2, $3)",
51-
values: ['George', 70, new Date(1946, 02, 14)]
52-
});
53-
54-
//subsequent queries with the same name will be executed without re-parsing the query plan by postgres
55-
client.query({
56-
name: 'insert beatle',
57-
values: ['Paul', 63, new Date(1945, 04, 03)]
58-
});
5945
var query = client.query("SELECT * FROM beatles WHERE name = $1", ['John']);
6046

6147
//can stream row results back 1 at a time
@@ -74,60 +60,27 @@ query.on('end', function() {
7460

7561
### Example notes
7662

77-
node-postgres supports both an 'event emitter' style API and a 'callback' style. The callback style is more concise and generally preferred, but the evented API can come in handy. They can be mixed and matched. The only events which do __not__ fire when callbacks are supplied are the `error` events, as they are to be handled by the callback function.
63+
node-postgres supports both an 'event emitter' style API and a 'callback' style. The callback style is more concise and generally preferred, but the evented API can come in handy when you want to handle row events as they come in.
64+
65+
They can be mixed and matched. The only events which do __not__ fire when callbacks are supplied are the `error` events, as they are to be handled within the callback function.
7866

79-
All examples will work with the pure javascript bindings (currently default) or the libpq native (c/c++) bindings (currently in beta)
67+
All examples will work with the pure javascript bindings or the libpq native (c/c++) bindings
8068

8169
To use native libpq bindings replace `require('pg')` with `require('pg').native`.
8270

8371
The two share the same interface so __no other code changes should be required__. If you find yourself having to change code other than the require statement when switching from `pg` to `pg.native`, please report an issue.
8472

85-
### Info
73+
### Features
8674

8775
* pure javascript client and native libpq bindings share _the same api_
88-
* _heavily_ tested
89-
* the same suite of 200+ integration tests passed by both javascript & libpq bindings
90-
* benchmark & long-running memory leak tests performed before releases
91-
* tested with with
92-
* postgres 8.x, 9.x
93-
* Linux, OS X
94-
* node 2.x & 4.x
9576
* row-by-row result streaming
96-
* built-in (optional) connection pooling
9777
* responsive project maintainer
9878
* supported PostgreSQL features
9979
* parameterized queries
10080
* named statements with query plan caching
101-
* async notifications
102-
* extensible js<->postgresql data-type coercion
103-
* query queue
104-
* active development
105-
* fast
106-
* close mirror of the node-mysql api for future multi-database-supported ORM implementation ease
107-
108-
### Contributors
109-
110-
Many thanks to the following:
111-
112-
* [creationix](https://github.com/creationix)
113-
* [felixge](https://github.com/felixge)
114-
* [pshc](https://github.com/pshc)
115-
* [pjornblomqvist](https://github.com/bjornblomqvist)
116-
* [JulianBirch](https://github.com/JulianBirch)
117-
* [ef4](https://github.com/ef4)
118-
* [napa3um](https://github.com/napa3um)
119-
* [drdaeman](https://github.com/drdaeman)
120-
* [booo](https://github.com/booo)
121-
* [neonstalwart](https://github.com/neonstalwart)
122-
* [homme](https://github.com/homme)
123-
* [bdunavant](https://github.com/bdunavant)
124-
* [tokumine](https://github.com/tokumine)
125-
* [shtylman](https://github.com/shtylman)
126-
* [cricri](https://github.com/cricri)
127-
* [AlexanderS](https://github.com/AlexanderS)
128-
* [ahtih](https://github.com/ahtih)
129-
* [chowey](https://github.com/chowey)
130-
* [kennym](https://github.com/kennym)
81+
* async notifications with `LISTEN/NOTIFY`
82+
* bulk import & export with `COPY TO/COPY FROM`
83+
* extensible js<->postgresql data-type coercion
13184

13285
## Documentation
13386

@@ -151,6 +104,35 @@ _if you use node-postgres in production and would like your site listed here, fo
151104

152105
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. I am usually available via google-talk at my github account public email address.
153106

107+
## Contributing
108+
109+
__I love contributions.__
110+
111+
You are welcome contribute via pull requests. If you need help getting the tests running locally feel free to email me or gchat me.
112+
113+
I will __happily__ accept your pull request if it:
114+
- _has tests_
115+
- looks reasonable
116+
- does not break backwards compatibility
117+
118+
If you need help or have questions about constructing a pull request I'll be glad to help out as well.
119+
120+
## Support
121+
122+
If at all possible when you open an issue please provide
123+
- version of node
124+
- version of postgres
125+
- smallest possible snippet of code to reproduce the problem
126+
127+
Usually I'll pop the code into the repo as a test. Hopefully the test fails. Then I make the test pass. Then everyone's happy!
128+
129+
## Extras
130+
131+
node-postgres is by design _low level_ with the bare minimum of abstraction. These might help out:
132+
133+
- https://github.com/grncdr/node-any-db
134+
- https://github.com/brianc/node-sql
135+
154136
## License
155137

156138
Copyright (c) 2010 Brian Carlson ([email protected])

benchmark/js-versus-native-bench.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)