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

livetex-node-pg

v2.0.1

Published

Multithreaded Postgres driver for Node-JS built with `libpq` and `libjemalloc`.

Downloads

3

Readme

Livetex-Node-Pg

Multithreaded Postgres driver for Node-JS built with libpq and libjemalloc.

####Install via npm: npm install livetex-node-pg

Examples

Simple query processing

var pg = require('livetex-node-pg');

pg.init(20, {
  'user': 'postgres',
  'dbname': 'postgres',
  'hostaddr': '127.0.0.1',
  'password': 'postgres'
});

pg.exec("SELECT 1 AS value", function(table) {
  console.log('Result table:', table);
}, console.error);

pg.exec("SELECT 2 AS another_value", function(table) {
  console.log('Result table:', table);
}, console.error);

You don't have to wait any connection ready events before calling exec or any other method.

Process destroying

var pg = require('livetex-node-pg');

pg.init(20, {
  'user': 'postgres',
  'dbname': 'postgres',
  'hostaddr': '127.0.0.1',
  'password': 'postgres'
});

pg.exec("SELECT 1 AS value", function(table) {
  console.log('Result table:', table);
}, console.error);

pg.destroy();

Nothing happen after destroy call.

Prepared queries

var pg = require('livetex-node-pg');
var preparedQuery = "SELECT $word1 AS word1, $word2 AS word2";

pg.init(20, {
  'user': 'postgres',
  'dbname': 'postgres',
  'hostaddr': '127.0.0.1',
  'password': 'postgres'
});

pg.execPrepared(preparedQuery, {
  'word1': 'hello',
  'word2': 'world'
}, function(table) {
  console.log('Result table:', table);
}, console.error);

pg.execPrepared(preparedQuery, {
  'word1': 'bye',
  'word2': 'bye'
}, function(table) {
  console.log('Result table:', table);
}, console.error);

You can pass different params to one prepared query.

API

Type definitions

  • pg.Row:Object.<string, (number|string|boolean|null)> - Table result row definition.
  • pg.Table:Array.<!pg.Row> - Definition of query result table.
  • pg.ResultHandler:?function(pg.Table) - Definition of function type to handle query execution result. Function argument - query result table.
  • pg.ErrorHandler:?function(string, number=) - Definition of function type to handle errors. Function arguments are error message string and optional error code.
  • pg.PreparedValue:?(number|string|boolean) - Definition of value types for insertion to prepared query.
  • pg.PreparedParams:Object.<string, (!pg.PreparedValue|!Array.<!pg.PreparedValue>)> - Definition of data object for query preparation.

Methods

pg.escapeString:string

Escapes strings in sql queries. For string escape we use dollar-quoting.

Arguments:

  • string:string Original string.

Returns escaped string.

pg.escapeArray:string

Escapes array of values. Array is casted to string of escaped elements divided by comma.

Arguments:

  • array:!Array.<!pg.PreparedValue> Array of values.

Returns escaped strings divided by comma.

pg.init: void

Initializes connections pool.

Arguments:

  • size: number Pool size - Count of pool connections.
  • options: !Object Connection options. Options must be an object with keys specified in documentation.
  • opt_errorHandler: !pg.ErrorHandler= Connection error handler. console.error will be used by default.

pg.exec: void

Executes SQL-query.

Arguments:

  • query: string SQL-query string.
  • complete: !pg.ResultHandler Success result handler.
  • cancel: !pg.ErrorHandler Execution error handler.

pg.execPrepared: void

Executes prepared SQL-query.

Arguments:

  • query: string Prepared SQL-query string.
  • params: !pg.PreparedParams Data object for query preparation.
  • complete: !pg.ResultHandler Success result handler.
  • cancel: !pg.ErrorHandler Execution error handler.

pg.prepareQuery: string

Prepares ready-to-use SQL-query.

Arguments:

  • query: string Prepared SQL-query string.
  • params: !pg.PreparedParams Data object for query preparation.

Returns ready-to-use SQL-query.

pg.destroy: void

Destroys connection pool.

License

Modified BSD License