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.io

v1.1.71

Published

Speed driver node js for postgres (100 000 request/sec and more), LISTEN, NOTIFY, pool, castom Types, minimal dependencies, sql file

Downloads

31

Readme

pg.io

Speed driver node js for PostgreSQL (100 000 request/sec and more), LISTEN, NOTIFY, pool, castom Types, minimal dependencies

Install

npm i pg.io

Сonnect

Сonnection is not explicit, you do not need to worry about it, you can immediately send requests

const PG = require('pg.io');

const db = new PG({
    user: 'username',
    password: 'password',
    database: 'database',
    rowFormat: 'JSON',
    max: 6
});

rowFormat: 'JSON' if you want the result of a string in JSON res = [{...},{...}...]

max: 6 The number of simultaneous connections to the database, balancing is based on the Round Robin principle.

Query

db.query('SELECT 1', (err, res) => {
  console.log(err, res);
});

let res = await db.query('SELECT 1');

db.query('SELECT $1', 1, (err, res) => {
  console.log(err, res);
});

db.query('SELECT $1::INT, $2::TEXT', 1, 'param', (err, res) => {
  console.log(err, res);
});

let res = await db.query('SELECT $1::INT, $2::TEXT', 1, 'param');

LISTEN, NOTIFY

db.on('Users.update', (id, name) => {
  console.log(id, name); //1, 'user';
});

db.emit('Users.update', 1, 'user');

These methods can be run on different machines or in different threads

db.emit this is the same as SELECT pg_notify("Users.update", '[1, "user"]'); or NOTIFY "Users.update", '[1, "user"]'

Custom types

You can determine how to convert a given specific type

114 - code JSON 3802 - code JSONb

select typname, typelem, typarray from pg_type; --return all code pg_type
db.setType(114, JSON.parse);
let res = await db.query('SELECT $1::JSON', JSON.stringify({name: 'maksim snytko'}));
console.log(res);//[ { json: { name: 'maksim snytko' } } ]

db.setType(1184, str => {
    return 'Minsk UNIX '+Date.parse(str);
});
let res = await db.query('SELECT now()');
console.log(res);//[{ now: 'Minsk UNIX 1513101706805'}]

Benchmark

PostgreSQL = 10

CPU = i7-6700HQ

OS = Windows 10

Node = 9.50

const PG = require('pg.io');

const db = new PG({
    user: 'postgres',
    password: 'password',
    database: 'postgres',
    max: 6
});

var k = 0;
console.time('test');
for (var i = 0; i < 1000000; i++) {
    db.query('SELECT 1', () => {
        if (++k === 1000000) {
            console.timeEnd('test');
        }
    });
}

test: 7618.609ms ~ 130 000 i/o sec