Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postgresql-client

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgresql-client

Enterprise level PostgreSQL client for JavaScript

  • 2.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24K
increased by13.04%
Maintainers
1
Weekly downloads
 
Created
Source

postgresql-client

NPM Version NPM Downloads CircleCI Test Coverage

Enterprise level PostgreSQL client for NodeJs and modern Web Browsers.

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
  • Named Prepared Statements
  • Cursors with fast double-link cache
  • Full binary wire protocol support for all data types
  • 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

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';

const connection = new Connection('postgres://localhost');
await connection.connect();
const result = await connection.query(
    'select * from cities where name like $1',
    {params: ['%york%']});
const rows = result.rows;
await connection.close(); // Disconnect

Establish a pooled connection, create a cursor

import {Pool} from 'postgresql-client';

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

const result = await db.query(
    'select * from cities where name like $1',
    {params: ['%york%'], cursor: true});
const cursor = result.cursor;
let row;
while ((row = cursor.next())) {
  console.log(row);
}

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

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 typeJS typeReceiveSend
boolbooleantext,binarybinary
int2numbertext,binarybinary
int4numbertext,binarybinary
int8BigInttext,binarybinary
float4numbertext,binarybinary
float8numbertext,binarybinary
charstringtext,binarybinary
bpcharstringtext,binarybinary
varcharstringtext,binarybinary
dateDatetext,binarybinary
timeDatetext,binarybinary
timestampDatetext,binarybinary
timestamptzDatetext,binarybinary
oidnumbertext,binarybinary
byteaBuffertext,binarybinary
uuidstringtext,binarybinary
jsonobjecttext,binarybinary
jsonbobjecttext,binarybinary
xmlstringtext,binarybinary
pointPointtext,binarybinary
circleCircletext,binarybinary
lsegRectangletext,binarybinary
boxRectangletext,binarybinary
_boolboolean[]text,binarybinary
_int2number[]text,binarybinary
_int4number[]text,binarybinary
_int8BigInt[]text,binarybinary
_float4number[]text,binarybinary
_float8number[]text,binarybinary
_charstring[]text,binarybinary
_bpcharstring[]text,binarybinary
_varcharstring[]text,binarybinary
_dateDate[]text,binarybinary
_timeDate[]text,binarybinary
_timestampDate[]text,binarybinary
_timestamptzDate[]text,binarybinary
_uuidstring[]text,binarybinary
_oidnumber[]text,binarybinary
_byteaBuffer[]text,binarybinary
_jsonobject[]text,binarybinary
_jsonbobject[]text,binarybinary
_xmlstring[]text,binarybinary
_pointPoint[]text,binarybinary
_circleCircle[]text,binarybinary
_lsegRectangle[]text,binarybinary
_boxRectangle[]text,binarybinary

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.

Keywords

FAQs

Package last updated on 23 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc