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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pg-ninja-library

v1.1.0

Published

Node.js library for creating a workspace for a PostgreSQL project

Readme

About

pg-ninja-library is a Node.js library for creating a workspace for a PostgreSQL project.

pg-ninja-library for study

  • Create a base of SQL queries and work with it using internal queries and transactions.
  • Execute queries and transactions by adding only binds to them.
  • The request can be changed in one place, without worrying about all the places where it is executed.
  • Use the workspace to teach students more easily and improve the efficiency of writing code. Including a lightweight syntax will reduce the amount of code for processing requests at times.

Navigation

Installation


$ npm i pg-ninja-library

usage

init workspace

const workspace = library(sql_queries_set: Object, connection: Object);

sql_queries_set - Object with key-value SQL queries

connection - PostgreSQL connection object from pg-ninja

setup workspace

./workspace/dataset/sql.js:

create SQL queries Object

const sql = {
    user: {
        info: 'SELECT * FROM users WHERE id = $1;',
        get_all: 'SELECT * FROM users;',
    },
    bank: {
        send_money: [
            'UPDATE bank SET balance = balance - $2 WHERE user_id = $1;',
            'UPDATE bank SET balance = balance + $2 WHERE user_id = $2;',
            "INSERT INTO transactions (transaction_type, from_user_id, to_user_id, amount) VALUES ('transfer', $1, $2, $3)",
        ]
    }
};

export default sql;

./workspace/init.js:

import libraries

import library from 'pg-ninja-library';
import { PG_Ninja } from 'pg-ninja-library';
import sql_dataset from './dataset/sql.js';

create PostgreSQL connection

const connection = new PG_Ninja({
    connectionString: process.env.PG_CONNECTION
});

create workspace

const workspace = new library(sql_dataset, connection);

export workspace

export default workspace;

Production

Now we have everything for start work with our workspace, so let's imagine, which functionality I can prepare depends on these SQL queries.

workspace.user.info:

user's account info we can use it fo user's perconal account for show information

import workspace from './workspace/init.js';

...

workspace.user.info.query([user_id]).then(res => {
    // res.rows[0] - all account info
}, err => {
    // some kind of error (?)
});

...

workspace.user.get_all:

may be helpful for statics, for data analytics, for business plans so let's make it more usefull with create Excel table from this script

import workspace from './workspace/init.js';

workspace.user.get_all.query().then(res => {
    res.to_excel('./reports/');
}, err => {});

workspace.bank.send_money:

so, I have the bank app and wanna create transfer function, but I must save data constistence. if user1 don't have enough money all next queries must be blocked.

How can I do it?

import workspace from './workspace/init.js';

...

workspace.bank.send_money.transaction([
    [5432, 200], // minus 200 dollars from user[id=5432]
    [2799, 200], // plus 200 dollars for user[id=2799]
    [5432, 2799, 200], // create transaction record about this operation really existed
]).then(res => {
    // we guaranteed all query procceded correctly
}, err => {
    // so now it's error, maybe not enough money or user[id=2799] have been blocked and deleted
});

...