npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

promise-pg

v0.1.1

Published

Promise wrapper for node-postgres

Readme

#promise-pg

Q promises wrapper for the node.js PostgreSQL client 'pg'.

Install

$ npm install promise-pg

Examples

Basic access

Basic Usage.

var pg = require("promise-pg");
pg.connect("postgres://example:1234@localhost:5432/example").spread(function(client, done) {
    var query = client.query({
        text: "select * from users",
        buffer: true //if set to true, adds all the rows to the result object available on the rows property on the promise resolve value
    }).promise.then(
              function(result) { console.log(result); }, //rowCount etc
              function(err) { throw err; },
              function(user) {} //for each row
          ).finally(done);
}).done();

Basic example

Transactions

When using transactions you only need to specify a function that will be executed when the connection is within the transaction, your function returns a promise objects, if it is resolved the transaction is commited, if it is rejected the transaction is rolled back.

var pg = require("promise-pg");
var Q = require("q");
pg.connect("postgres://example:1234@localhost:5432/example").spread(function(client, done) {
    var INSERT = "INSERT INTO users(name, t_birth, country) VALUES ($1, $2, $3);";
    console.log("Transaction I:")
    var trans = client.transaction(function() {
        //This code runs in a transaction and should return a promise object, that when resolved the transaction is committed
        //But when rejected the transaction is rolled back.
        return Q.all([
            {
                text: INSERT,
                values: ["Jake1", "now()", "Oo"]
            },
            {
                text: INSERT,
                values: ["Cake2", null, "Küche"]
            },
            {
                text: INSERT,
                values: ["Mike3", "now()", null]
            }
        ].map(function(q) {
            return client.query(q).promise;
        }));
    }).then(function() {
            console.log("Good - Committed Transaction I."); //This will happen
        }, function(err) {
            console.log("Bad - Rolled back Transaction I.", err);
        }); //Not returning the connection to the pool yet


    trans.finally(function() { //after this transaction
        client.transaction(function() {
            //This code runs in a transaction and should return a promise object, that when resolved the transaction is committed
            //But when rejected the transaction is rolled back.

            return Q.all([
                {
                    text: INSERT,
                    values: ["Jake", "now()", "Oo"]
                },
                {
                    text: INSERT, //Bad, name is NOT NULL
                    values: [null, null, "Küche"]
                },
                {
                    text: INSERT,
                    values: ["Mike", "now()", null]
                }
            ].map(function(q) {
                return  client.query(q).promise;
            }));
        }).then(function() {
                console.log("Bad - Committed Transaction II."); //Cannot commit due to bad name
            }, function(err) {
                console.log("Good - Rolled back Transaction II.", err.message);
            }).finally(done).done();
    });
}).done();

Contributing

We appreciate any contributions!

If you need help getting the package to run, please feel free to message me .

License

Apache 2.0 License