| var Client = require('../'); | ||
| var async = require('async'); | ||
| var ok = require('okay'); | ||
| describe('many connections', function() { | ||
| describe('async', function() { | ||
| var test = function(count, times) { | ||
| it('connecting ' + count + ' clients ' + times, function(done) { | ||
| this.timeout(10000); | ||
| var connectClient = function(n, cb) { | ||
| var client = new Client(); | ||
| client.connect(ok(cb, function() { | ||
| client.query('SELECT NOW()', ok(cb, function() { | ||
| client.end(cb); | ||
| })); | ||
| })); | ||
| } | ||
| var run = function(n, cb) { | ||
| async.times(count, connectClient, cb); | ||
| } | ||
| async.timesSeries(times, run, done); | ||
| }); | ||
| }; | ||
| test(1, 1); | ||
| test(1, 1); | ||
| test(1, 1); | ||
| test(5, 5); | ||
| test(5, 5); | ||
| test(5, 5); | ||
| test(10, 10); | ||
| test(10, 10); | ||
| test(10, 10); | ||
| test(20, 20); | ||
| test(20, 20); | ||
| test(20, 20); | ||
| test(30, 10); | ||
| test(30, 10); | ||
| test(30, 10); | ||
| }); | ||
| }); |
| var Client = require('../'); | ||
| var async = require('async'); | ||
| var ok = require('okay'); | ||
| var assert = require('assert'); | ||
| describe('many errors', function() { | ||
| it('functions properly without segfault', function(done) { | ||
| var throwError = function(n, cb) { | ||
| var client = new Client() | ||
| client.connectSync() | ||
| var doIt = function(n, cb) { | ||
| client.query('select asdfiasdf', function(err) { | ||
| assert(err, 'bad query should emit an error'); | ||
| cb(null); | ||
| }); | ||
| }; | ||
| async.timesSeries(10, doIt, function(err) { | ||
| if(err) return cb(err); | ||
| client.end(cb); | ||
| }); | ||
| }; | ||
| async.times(10, throwError, done); | ||
| }); | ||
| }); |
+3
-1
@@ -5,3 +5,5 @@ language: node_js | ||
| - "0.11" | ||
| before_install: | ||
| - npm install npm --global | ||
| env: | ||
| - PGUSER=postgres | ||
| - PGUSER=postgres PGDATABASE=postgres |
+15
-13
@@ -46,4 +46,3 @@ var Libpq = require('libpq'); | ||
| Client.prototype._mapResults = function(pq) { | ||
| var rows = []; | ||
| Client.prototype._parseResults = function(pq, rows) { | ||
| var rowCount = pq.ntuples(); | ||
@@ -99,2 +98,4 @@ var colCount = pq.nfields(); | ||
| if(!pq.consumeInput()) { | ||
| //if consumeInput returns false | ||
| //than a read error has been encountered | ||
| return this._readError(); | ||
@@ -110,6 +111,11 @@ } | ||
| //load our result object | ||
| var rows = [] | ||
| while(pq.getResult()) { | ||
| if(pq.resultStatus() == 'PGRES_TUPLES_OK') { | ||
| this._parseResults(this.pq, rows); | ||
| } | ||
| if(pq.resultStatus() == 'PGRES_COPY_OUT') break; | ||
| } | ||
| var status = pq.resultStatus(); | ||
@@ -123,3 +129,3 @@ switch(status) { | ||
| case 'PGRES_EMPTY_QUERY': { | ||
| this.emit('result'); | ||
| this.emit('result', rows); | ||
| break; | ||
@@ -161,6 +167,6 @@ } | ||
| var onResult = function() { | ||
| var onResult = function(rows) { | ||
| self.removeListener('error', onError); | ||
| self.removeListener('result', onResult); | ||
| cb(null); | ||
| cb(null, rows); | ||
| }; | ||
@@ -216,5 +222,3 @@ this.once('error', onError); | ||
| self._awaitResult(function(err) { | ||
| return cb(err, err ? null : self._mapResults(self.pq, self.types)); | ||
| }); | ||
| self._awaitResult(cb) | ||
| }); | ||
@@ -244,5 +248,3 @@ }; | ||
| if(err) return cb(err); | ||
| self._awaitResult(function(err) { | ||
| return cb(err, err ? null : self._mapResults(self.pq, self.types)); | ||
| }); | ||
| self._awaitResult(cb) | ||
| }); | ||
@@ -273,3 +275,3 @@ }; | ||
| throwIfError(this.pq); | ||
| return this._mapResults(pq, this.types); | ||
| return this._parseResults(pq, []); | ||
| }; | ||
@@ -285,3 +287,3 @@ | ||
| throwIfError(this.pq); | ||
| return this._mapResults(this.pq, this.types); | ||
| return this._parseResults(this.pq, []); | ||
| }; | ||
@@ -288,0 +290,0 @@ |
+3
-2
| { | ||
| "name": "pg-native", | ||
| "version": "1.5.0", | ||
| "version": "1.7.2", | ||
| "description": "A slightly nicer interface to Postgres over node-libpq", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "libpq": "1.2.1", | ||
| "libpq": "1.4.1", | ||
| "pg-types": "1.6.0", | ||
@@ -31,2 +31,3 @@ "readable-stream": "1.0.31" | ||
| "devDependencies": { | ||
| "generic-pool": "^2.1.1", | ||
| "async": "^0.9.0", | ||
@@ -33,0 +34,0 @@ "concat-stream": "^1.4.6", |
+14
-3
@@ -9,5 +9,16 @@ #node-pg-native | ||
| You need PostgreSQL client headers installed. On OS X `brew install postgres`. On Ubuntu `apt-get install libpq-dev`. Afterwards `pg_config` should be in your path. Then... | ||
| You need PostgreSQL client libraries & tools installed. An easy way to check is to type `pg_config`. If `pg_config` is in your path, you should be good to go. If it's not in your path you'll need to consult operating specific instructions on how to go about getting it there. | ||
| ```bash | ||
| Some ways I've done it in the past: | ||
| - On OS X: `brew install postgres` | ||
| - On Ubuntu: `apt-get install libpq-dev` | ||
| - On Windows: | ||
| 1. Install Visual Studio C++ (successfully built with Express 2010). Express is free. | ||
| 2. Add your Postgre Installation's `bin` folder to the system path (i.e. `C:\Program Files\PostgreSQL\9.3\bin`). | ||
| 3. Make sure that both `libpq.dll` and `pg_config.exe` are in that folder. | ||
| Afterwards `pg_config` should be in your path. Then... | ||
| ```sh | ||
| $ npm i pg-native | ||
@@ -69,3 +80,3 @@ ``` | ||
| Because `pg-native` is bound to [libpq](https://github.com/brianc/node-libpq) it is able to provide _sync_ operations for both connecting and queries. This is a bad idea in _non-blocking systems_ such as web servers, but is exteremly convienent in scripts and bootstrapping applications - much the same way `fs.readFileSync` comes in handy. | ||
| Because `pg-native` is bound to [libpq](https://github.com/brianc/node-libpq) it is able to provide _sync_ operations for both connecting and queries. This is a bad idea in _non-blocking systems_ like web servers, but is exteremly convienent in scripts and bootstrapping applications - much the same way `fs.readFileSync` comes in handy. | ||
@@ -72,0 +83,0 @@ ```js |
@@ -22,5 +22,5 @@ var Client = require('../'); | ||
| assert.strictEqual(res[0][1], null) | ||
| done(); | ||
| client.end(done); | ||
| }); | ||
| }); | ||
| }); |
@@ -29,5 +29,5 @@ var Client = require('../'); | ||
| assert.equal(rows[0].when, 'blah'); | ||
| done(); | ||
| client.end(done); | ||
| })); | ||
| }); | ||
| }); |
@@ -11,2 +11,6 @@ var Client = require('../') | ||
| after(function(done) { | ||
| this.client.end(done); | ||
| }); | ||
| it('works', function(done) { | ||
@@ -13,0 +17,0 @@ var params = ['']; |
+2
-1
@@ -27,3 +27,4 @@ var Client = require('../') | ||
| it('works with args', function() { | ||
| Client().connectSync('host=localhost'); | ||
| var args = 'host=' + (process.env.PGHOST || 'localhost') | ||
| Client().connectSync(args); | ||
| }); | ||
@@ -30,0 +31,0 @@ |
@@ -5,8 +5,29 @@ var Client = require('../'); | ||
| describe('multiple commands in a single query', function() { | ||
| before(function(done) { | ||
| this.client = new Client() | ||
| this.client.connect(done) | ||
| }) | ||
| after(function(done) { | ||
| this.client.end(done) | ||
| }) | ||
| it('all execute to completion', function(done) { | ||
| var client = new Client(); | ||
| client.connectSync(); | ||
| client.query("SELECT NOW(); SELECT 'brian'::text as name", function(err, rows) { | ||
| this.client.query("SELECT '10'::int as num; SELECT 'brian'::text as name", function(err, rows) { | ||
| assert.ifError(err); | ||
| assert.equal(rows.length, 2, 'should return two rows'); | ||
| assert.equal(rows[0].num, '10'); | ||
| assert.equal(rows[1].name, 'brian'); | ||
| done(); | ||
| }); | ||
| }); | ||
| it('inserts and reads at once', function(done) { | ||
| var txt = 'CREATE TEMP TABLE boom(age int);'; | ||
| txt += 'INSERT INTO boom(age) VALUES(10);'; | ||
| txt += 'SELECT * FROM boom;'; | ||
| this.client.query(txt, function(err, rows) { | ||
| assert.ifError(err); | ||
| assert.equal(rows.length, 1); | ||
| assert.equal(rows[0].name, 'brian'); | ||
| assert.equal(rows[0].age, 10); | ||
| done(); | ||
@@ -13,0 +34,0 @@ }); |
+6
-2
@@ -14,3 +14,5 @@ var Client = require('../'); | ||
| async.timesSeries(10, exec, cb); | ||
| async.timesSeries(10, exec, ok(cb, function() { | ||
| client.end(cb); | ||
| })); | ||
| }; | ||
@@ -39,3 +41,5 @@ | ||
| }; | ||
| async.timesSeries(10, exec, cb); | ||
| async.timesSeries(10, exec, ok(cb, function() { | ||
| client.end(cb); | ||
| })); | ||
| }; | ||
@@ -42,0 +46,0 @@ |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
45808
7.3%29
7.41%1147
8.41%305
3.74%8
14.29%+ Added
- Removed
Updated