Skip to content

Commit 13ba76b

Browse files
committed
Merge pull request brianc#657 from brianc/libpq
Rewrite native bindings
2 parents 03978b6 + aa901a2 commit 13ba76b

35 files changed

+383
-2104
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- "0.10"
4+
- "0.11"
45
before_script:
56
- node script/create-test-tables.js pg://postgres@127.0.0.1:5432/postgres
67
env:

Makefile

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,26 @@ params := $(connectionString)
77
node-command := xargs -n 1 -I file node file $(params)
88

99
.PHONY : test test-connection test-integration bench test-native \
10-
build/default/binding.node jshint upgrade-pg publish
10+
jshint publish test-missing-native update-npm
1111

1212
all:
1313
npm install
1414

15-
build:
16-
node-gyp rebuild
17-
1815
help:
1916
@echo "make prepare-test-db [connectionString=postgres://<your connection string>]"
2017
@echo "make test-all [connectionString=postgres://<your connection string>]"
2118

2219
test: test-unit
2320

24-
test-all: jshint test-unit test-integration test-native test-binary
21+
test-all: jshint test-missing-native test-unit test-integration test-native test-binary
2522

26-
test-travis: test-all upgrade-pg
27-
#@make test-all connectionString=postgres://postgres@localhost:5433/postgres
2823

29-
upgrade-pg:
30-
#@chmod 755 script/travis-pg-9.2-install.sh
31-
#@./script/travis-pg-9.2-install.sh
24+
udpate-npm:
25+
@npm i npm --global
3226

3327
bench:
3428
@find benchmark -name "*-bench.js" | $(node-command)
3529

36-
build/default/binding.node:
37-
@node-gyp rebuild
38-
3930
test-unit:
4031
@find test/unit -name "*-tests.js" | $(node-command)
4132

@@ -47,12 +38,23 @@ test-connection-binary:
4738
@echo "***Testing binary connection***"
4839
@node script/test-connection.js $(params) binary
4940

50-
test-native: build/default/binding.node
41+
test-missing-native:
42+
@echo "***Testing optional native install***"
43+
@rm -rf node_modules/pg-native
44+
@node test/native/missing-native.js
45+
@npm install pg-native@1.4.0
46+
@node test/native/missing-native.js
47+
@rm -rf node_modules/pg-native
48+
49+
node_modules/pg-native/index.js:
50+
@npm i pg-native
51+
52+
test-native: node_modules/pg-native/index.js
5153
@echo "***Testing native bindings***"
5254
@find test/native -name "*-tests.js" | $(node-command)
5355
@find test/integration -name "*-tests.js" | $(node-command) native
5456

55-
test-integration: test-connection build/default/binding.node
57+
test-integration: test-connection
5658
@echo "***Testing Pure Javascript***"
5759
@find test/integration -name "*-tests.js" | $(node-command)
5860

@@ -67,7 +69,3 @@ prepare-test-db:
6769
jshint:
6870
@echo "***Starting jshint***"
6971
@./node_modules/.bin/jshint lib
70-
71-
publish:
72-
@rm -r build || (exit 0)
73-
@npm publish

binding.gyp

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

lib/client.js

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ var ConnectionParameters = require(__dirname + '/connection-parameters');
77
var Query = require(__dirname + '/query');
88
var defaults = require(__dirname + '/defaults');
99
var Connection = require(__dirname + '/connection');
10-
var CopyFromStream = require(__dirname + '/copystream').CopyFromStream;
11-
var CopyToStream = require(__dirname + '/copystream').CopyToStream;
1210

1311
var Client = function(config) {
1412
EventEmitter.call(this);
@@ -130,17 +128,6 @@ Client.prototype.connect = function(callback) {
130128
self.activeQuery.handleCopyInResponse(self.connection);
131129
});
132130

133-
con.on('copyOutResponse', function(msg) {
134-
if(self.activeQuery.stream === undefined) {
135-
self.activeQuery._canceledDueToError = new Error('No destination stream defined');
136-
//canceling query requires creation of new connection
137-
//look for postgres frontend/backend protocol
138-
//TODO - this needs to die/be refactored
139-
(new self.constructor({port: self.port, host: self.host}))
140-
.cancel(self, self.activeQuery);
141-
}
142-
});
143-
144131
con.on('copyData', function (msg) {
145132
self.activeQuery.handleCopyData(msg, self.connection);
146133
});
@@ -185,13 +172,13 @@ Client.prototype.connect = function(callback) {
185172
con.once('end', function() {
186173
if ( callback ) {
187174
// haven't received a connection message yet !
188-
var err = new Error('Connection was ended during query');
175+
var err = new Error('Connection terminated');
189176
callback(err);
190177
callback = null;
191178
return;
192179
}
193180
if(self.activeQuery) {
194-
var disconnectError = new Error('Connection was ended during query');
181+
var disconnectError = new Error('Connection terminated');
195182
self.activeQuery.handleError(disconnectError, con);
196183
self.activeQuery = null;
197184
}
@@ -209,9 +196,8 @@ Client.prototype.getStartupConf = function() {
209196
var params = this.connectionParameters;
210197

211198
var data = {
212-
user : params.user ,
213-
database : params.database
214-
// client_encoding : "'".concat(params.client_encoding).concat("'")
199+
user: params.user,
200+
database: params.database
215201
};
216202

217203
var appName = params.application_name || params.fallback_application_name;
@@ -301,30 +287,12 @@ Client.prototype._pulseQueryQueue = function() {
301287
}
302288
};
303289

304-
Client.prototype._copy = function (text, stream) {
305-
var config = {};
306-
config.text = text;
307-
config.stream = stream;
308-
config.callback = function (error) {
309-
if(error) {
310-
config.stream.error(error);
311-
} else {
312-
config.stream.close();
313-
}
314-
};
315-
var query = new Query(config);
316-
this.queryQueue.push(query);
317-
this._pulseQueryQueue();
318-
return config.stream;
319-
320-
};
321-
322290
Client.prototype.copyFrom = function (text) {
323-
return this._copy(text, new CopyFromStream());
291+
throw new Error("For PostgreSQL COPY TO/COPY FROM support npm install pg-copy-streams");
324292
};
325293

326294
Client.prototype.copyTo = function (text) {
327-
return this._copy(text, new CopyToStream());
295+
throw new Error("For PostgreSQL COPY TO/COPY FROM support npm install pg-copy-streams");
328296
};
329297

330298
Client.prototype.query = function(config, values, callback) {

0 commit comments

Comments
 (0)