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 = ; const db = 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; let res = await db; db; db; let res = await db;
LISTEN, NOTIFY
db; db;
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;let res = await db;console;//[ { json: { name: 'maksim snytko' } } ] db;let res = await db;console;//[{ now: 'Minsk UNIX 1513101706805'}]
Benchmark
PostgreSQL = 10
CPU = i7-6700HQ
OS = Windows 10
Node = 9.50
const PG = ; const db = user: 'postgres' password: 'password' database: 'postgres' max: 6; var k = 0;console;for var i = 0; i < 1000000; i++ db;
test: 7618.609ms ~ 130 000 i/o sec