Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

q-postgres

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

q-postgres - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

.node-version

6

package.json
{
"name": "q-postgres",
"version": "1.0.3",
"version": "1.0.4",
"description": "Postgres with promises.",

@@ -22,5 +22,5 @@ "main": "q-postgres.js",

"engines": {
"node": "~4.2.2",
"npm": "~2.14.7"
"node": "~4.3.1",
"npm": "~3.7.3"
}
}
'use strict';
var Promise = require('q').Promise;
var q = require('q');
var Postgres = require('pg');
var PgWrapper = require('./pg.wrapper');
function PgPromise(user, pass, host, base) {
function PgPromise(user, pass, host, base, url) {
var pgPromise = this;
user = String(user);
pass = String(pass);
host = String(host);
base = base && String(base).length ? '/'.concat(base) : '';
var connString = url;
var connString = 'pg://'.concat(user, ':', pass, '@', host, base);
if (!url) {
user = String(user);
pass = String(pass);
host = String(host);
base = base && String(base).length ? '/'.concat(base) : '';
connString = 'pg://'.concat(user, ':', pass, '@', host, base);
}
pgPromise.connect = function() {
return Promise(function(resolve, reject) {
return q.Promise(function(resolve, reject) {
Postgres.connect(connString, function(err, client, done) {

@@ -19,0 +22,0 @@ if (err) {

# q-postgres
Postgres with promises.
### Sample
```javascript
var env = process.env.NODE_ENV || 'development';
var props = require('./server.json')[env];
var db = props.db;
var poolPostgres = new qPostgres(db.user, db.pass, db.host, db.base, process.env.DATABASE_URL);
//Get connection from pool
poolPostgres.connect().then(function(connection) {
//open transaction
return connection.openTransaction().then(createTableMigrations).then(function(transaction) {
var sql = 'SELECT * FROM table_name';
return transaction.runScript(sql).then(function(res) {
//commit transaction
returm transaction.commit().then(function() {
//Promise result
return res.rows;
});
}).catch(transaction.rollback); //rollback transaction
}).then(function() {
connection.end(); //Leave connection from pool
});
});
```
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