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

pg-supp

v1.2.5

Published

light-weight library to simplify postgreSQL database queries and return queries as promises

Downloads

58

Readme

current methods

your_db.getAll(table) - gets all rows and columns from provided table
your_db.getSpecific(table, condition) - gets all rows and columns from provided table where the specified condition is met
your_db.getColumn(table, column) - gets all rows from provided table within given column
your_db.insert(table, columns, values, returnValue) - inserts to provided table with given columns and values.  returnValue is optional, will return all if none is given (can be ignored for general usage)
your_db.update(table, columns, newValues, condition) - updates provided table at specified columns with given newValues at points that meet condition
your_db.deleteAll(table) - deletes all rows and columns from provided table
your_db.deleteSpecific(table, condition) - deletes all rows and columns from provided table where the specificed condition is met

methods coming soon

orderBy
createDatabase
createTable
createJoinTable

Usage

Install using:

npm install pg-supp [args]

Require the pg and pg-supp module as follows:

var pg = require('pg');
var pgs = require('pg-supp');

Host must already be established and database must already be created. Instantiate your database with pg-supp by invoking constructor function:

var yourDBVariable = new pgs('your_db_name', 'your_host');
OR
var yourDBVariable = new pgs('your_db_name');

If host is not provided it will default to 'postgres://@localhost/'. You can provide username/password with the host if needed:

var yourDBVariable = new pgs('your_db_name', 'postgres://username:password@localhost/database')

Multiple databases with different or same hosts can be established and used in this way:

var yourFirstDBVariable = new pgs('db_name', 'host');
var yourSecondDBVariable = new pgs('other_db_name', 'other_host');
var yourThirdDBVariable = new pgs('db_name', 'host')

Now, all your DBVariables have access to all methods pg-supp exposes and will act on corresponding databases/hosts.

All pg-supp methods return promises. Users might need to require the promise module or an alternative for particular use cases.

Examples

Bear in mind all .then(...) functionality is from the promise npm and isn't required to use. Each of the following examples can be implemented with each pg-supp method.

For all examples I will use the table 'users' with the columns 'name' and 'age', and an id that is a serial primary key.

Without .then:

yourDBVariable.insert('users', ['name', 'age'], ['richard', 35]);
yourDBVariable.deleteSpecific('users', 'name = richard');

With .then:

yourDBVariable.getSpecific('users', 'name = richard AND age = 35')
  .then(function (repsonse) {
    //promise code goes here
    //simple example below
    console.log(reponse);
    return response;
  });

Inside of an express app:

var express = require('express');
var router = express.Router();

var pg = require('pg');
var pgs = require('pgs');

var myDB = new pgs('db_name');

router.get('/api/users', function(req, res, next) {
  myDb.getAll('users')
    .then(function (response) {
      res.send(response);
      return;
    });
}