Socket
Socket
Sign inDemoInstall

pg-native

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-native - npm Package Compare versions

Comparing version 1.5.0 to 1.7.2

test/many-connections.js

28

index.js

@@ -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 @@

{
"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",

@@ -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 = [''];

@@ -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 @@ });

@@ -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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc