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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ppooled-pg

v0.4.0

Published

Promisified PostgreSQL driver with more effective pooling strategies.

Downloads

6

Readme

ppooled-pg

Promisified PostgreSQL driver with more effective pooling strategies.

Brief

This is simply a personal promise wrapper for wonderful but non promise aware PostgreSQL driver pooled-pg.

This is not intended, at least nowadays, to be a complete full-featured tool. This only has methods I found handy for my own purposes.

But push requests are welcome if anyone is interested in improving it.

Índex

Setup

    npm install ppooled-pg

Usage

Instantiation


var pPooled = require("ppooled-pg");

var ppg = pPooled({
    protocol: "postgresql", // "postgresql" (default) or "remote".
                        // See https://www.npmjs.com/package/pooled-pg#advanced-usage-remote-mode
    user: "db_user_name",
    password: "db_user_password",
    connect: "db_user_connect_string",
        // See pooled-pg documenetation for more details on connect string:
        // https://www.npmjs.com/package/pooled-pg
});

Promisified methods

query(sql, args)

Simple wrapper to pooled-pg query method.

var q = ppg.query(sql, args);

q.then(function(result){
    console.log(result);
    // result.rows = Actual result data.
}.catch(function(err){
    console.error(err);
    // Some error happened.
});

queryRows(sql, args)

Like query() but strip out all metadata retuning just resulting rows (more handy if you don't care about other stuff).

var q = ppg.queryRows(sql, args);

q.then(function(result){
    console.log(result);
    // result = Actual result data.
}.catch(function(err){
    console.error(err);
    // Some error happened.
});

Synchronous methods

Synchronous methods works just the same as its promisified counterparts (in fact they are just wrappers over them) but returns data syncronously instead of as promise.

It may seem weird having synchronous methods in a promise library. But sometimes is Ok to read some data synchronously. Specially at startup, when is so common having to read common parameters that are needed for almost all the rest of the process.

Having synchronous methods saves us to be forced to install another PostgresSQL library to do just that and, most importantly, dealing with different syntax and / or outcome formatting.

querySync(sql, args):

try {
    console.log(ppg.querySync(sql, args));
} catch (err) {
    console.error(err);
    // Some error happened.
};

queryRowsSync(sql, args):

try {
    console.log(ppg.queryRowsSync(sql, args));
} catch (err) {
    console.error(err);
    // Some error happened.
};

Advanced Features

Support for SQL Tagged Templates

SQL Tagged Templates (SQLTT) version 0.0.2 or higher are supported from ppooled-pg 0.3.0.

That means we can pass an SQLTT instance instead of actual SQL string.

In this case, proper PostgreSQL version of its SQL will be picked up and parameters will be parsed through its args() method.

arguments Symbol

WARNING: This feature was introduced before SQL Tagged Templates and is mantained due to backward compatibility reasons. But it could be removed in future versions (in which case major version number would be increased too).

Passing arguments as an array can be awkward sometimes. Specially if you have a lot of them.

JSON objects are much more handy, but most SQL engines only accept arguments as positional parameters.

ppooled-pg takes advantadge of ES6+ wonderful Symbol feature to allow providing SQL as a String object with optional "arguments" symbol for that.

Example:

const $args$ = Symbol.for("arguments");

const sql = new String(`
    select foo from bar
    where baz = $1
    and foobar = $2
`);

sql[$args$] = ["baz", "foobar"];

ppg.queryRows(sql, {
  foobar: "foobar value",
  baz: "baz value"
}).then(data=>console.log(data));

Also, not provided values are silently replaced by nulls as well so, for inserts and updates, there is no need to pass all parameters if they aren't declared as 'NOT NULL' or have a default value.

Contributing

If you are interested in contributing with this project, you can do it in many ways:

  • Creating and/or mantainig documentation.

  • Implementing new features or improving code implementation.

  • Reporting bugs and/or fixing it.

  • Sending me any other feedback.

  • Whatever you like...

Please, contact-me, open issues or send pull-requests thought this project GIT repository