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

postgresql-client

v2.11.0

Published

Enterprise level PostgreSQL client for JavaScript

Downloads

124,764

Readme

postgresql-client

NPM Version NPM Downloads CircleCI Test Coverage

Enterprise level PostgreSQL client for NodeJs

Library

  • Pure JavaScript library completely written in TypeScript
  • Works with both CommonJS and ESM module systems
  • Well tested
  • Strictly typed
  • Asynchronous Promise based api

Features

  • Both single connection and advanced pooling support
  • Full binary wire protocol support for all data types
  • Named Prepared Statements
  • Cursors with fast double-link cache
  • High level implementation for notifications (LISTEN/NOTIFY)
  • Extensible data-types and type mapping
  • Bind parameters with OID mappings
  • Multidimensional arrays with fast binary encoding/decoding
  • Low memory utilization and boosted performance with Shared Buffers
  • Supports Clear text, MD5 and SASL password algorithms
  • Can return both array and object rows
  • Auto disposal with "using" syntax (TC30 Explicit Resource Management)

Installation

$ npm install postgresql-client --save

Documentation

Please read :small_orange_diamond: DOCUMENTATION :small_orange_diamond: for detailed usage.

Example usage

Establish a single connection, execute a simple query

import {Connection} from 'postgresql-client';
// Create connection
const connection = new Connection('postgres://localhost');
// Connect to database server
await connection.connect();

// Execute query and fetch rows
const result = await connection.query(
    'select * from cities where name like $1',
    {params: ['%york%']});
const rows: any[] = result.rows;
// Do what ever you want with rows

// Disconnect from server
await connection.close(); 

Establish a pooled connection, create a cursor

import {Pool} from 'postgresql-client';

// Create connection pool
const db = new Pool({
    host: 'postgres://localhost',
    pool: {
       min: 1,
       max: 10,
       idleTimeoutMillis: 5000
    }
});

// Execute query and fetch cursor
const result = await db.query(
    'select * from cities where name like $1',
    {params: ['%york%'], cursor: true});

// Walk through the cursor, and do whatever you want with fetched rows
const cursor = result.cursor;
let row;
while ((row = await cursor.next())) {
  console.log(row);
}
// Close cursor, (Send connection back to the pool)
await cursor.close();

// Disconnect all connections and shutdown pool
await db.close(); 

Using prepared statements

import {DataTypeOIDs} from 'postgresql-client'; 

// .....
const statement = await connection.prepare( 
    'insert into my_table(id, name) values ($1, $2)', {
        paramTypes: [DataTypeOIDs.Int4, DataTypeOIDs.Varchar]
    });

for (let i = 0; i < 100; i++) {
    await statement.execute({params: [i, ('name' + i)]});
}
await statement.close(); // When you done, close the statement to relase resources

Check DOCUMENTATION for other examples.

Type mappings

The table below lists builtin data type mappings.

| Posgtres type | JS type | Receive | Send | |---------------|:------------|-------------|--------| | bool | boolean | text,binary | binary | | int2 | number | text,binary | binary | | int4 | number | text,binary | binary | | int8 | BigInt | text,binary | binary | | float4 | number | text,binary | binary | | float8 | number | text,binary | binary | | char | string | text,binary | binary | | bpchar | string | text,binary | binary | | varchar | string | text,binary | binary | | date | Date | text,binary | binary | | time | Date | text,binary | binary | | timestamp | Date | text,binary | binary | | timestamptz | Date | text,binary | binary | | oid | number | text,binary | binary | | bytea | Buffer | text,binary | binary | | uuid | string | text,binary | binary | | json | object | text,binary | binary | | jsonb | object | text,binary | binary | | xml | string | text,binary | binary | | point | Point | text,binary | binary | | circle | Circle | text,binary | binary | | lseg | Rectangle | text,binary | binary | | box | Rectangle | text,binary | binary | | int2Vector | number[] | text,binary | binary | | _bool | boolean[] | text,binary | binary | | _int2 | number[] | text,binary | binary | | _int4 | number[] | text,binary | binary | | _int8 | BigInt[] | text,binary | binary | | _float4 | number[] | text,binary | binary | | _float8 | number[] | text,binary | binary | | _char | string[] | text,binary | binary | | _bpchar | string[] | text,binary | binary | | _varchar | string[] | text,binary | binary | | _date | Date[] | text,binary | binary | | _time | Date[] | text,binary | binary | | _timestamp | Date[] | text,binary | binary | | _timestamptz | Date[] | text,binary | binary | | _uuid | string[] | text,binary | binary | | _oid | number[] | text,binary | binary | | _bytea | Buffer[] | text,binary | binary | | _json | object[] | text,binary | binary | | _jsonb | object[] | text,binary | binary | | _xml | string[] | text,binary | binary | | _point | Point[] | text,binary | binary | | _circle | Circle[] | text,binary | binary | | _lseg | Rectangle[] | text,binary | binary | | _box | Rectangle[] | text,binary | binary | | _int2Vector | number[][] | text,binary | binary |

Support

You can report bugs and discuss features on the GitHub issues page When you open an issue please provide version of NodeJS and PostgreSQL server.

Node Compatibility

  • node >= 14.x

License

postgresql-client is available under MIT license.