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

lupdo-postgres

v2.0.0

Published

PostgreSql Driver For Lupdo

Downloads

29

Readme

Lupdo-postgres

Lupdo Driver For PostgreSql and CockroachDB. Api

Supported Databases

Third Party Library

Lupdo-postgres, under the hood, uses stable and performant npm packages:

Usage

Base Example

const { createPostgresPdo } = require('lupdo-postgres');
// ES6 or Typescrypt
import { createPostgresPdo } from 'ludpo-postgres';

const pdo = createPostgresPdo(
    {
        host: 'localhost',
        port: 5432,
        user: 'user',
        password: 'password',
        database: 'database'
    },
    { min: 2, max: 3 }
);

const run = async () => {
    const statement = await pdo.query('SELECT 2');
    const res = statement.fetchArray().all();
    console.log(res);
    await pdo.disconnect();
};

run();

Driver Options

https://node-postgres.com/apis/client

Note The host option also accepts a list of host:port the pool will generate the connection using a random host from the list.

Pg Overrides

By default Ludpo-sqlite overrides user connection options with this:

{
    types: customParser;
}

Lupdo postgres has a custom type parser

  • boolean are returned as number 1 or 0
  • int8 are returned as number or BigInt when necessary
  • bytea are returned as Buffer
  • all others types are always returned as string
  • array are returned as Javascript Array of corresponding parsed type

Parameters Binding

Lupdo-postgres ignore type definition of TypeBinding parameter.
Lupdo-postgres support array of parameters.

Postgres Named Parameter

Lupdo-postgres support named parameter with syntax :name, through the package yesql

Postgres Numeric Parameter

Lupdo-postgres support numeric parameter with syntax ?, you can escape it using syntax ??.

Kill Connection

Lupdo-postgres support kill query (only for Postgress Database not CockroachDB).

Postgres Returing

Lupdo-postgres support queries with returning, results can be fetched from statement.

const stmt = pdo.query("INSERT INTO users (name, gender) VALUES ('Claudio', 'All') returning *;");
console.log(stmt.fetchArray().all());
/*
[
    [33, 'Claudio', 'All']
]
*/

Postgres lastInsertId

When pdo.query() is executed outside a transaction, lupdo-postgres automatically try to fetch LastInsertId and if available it will return last id when stmt.lastInsertId() is called.

Lupdo-postgres can fetch LastInsertId on real-time when called inside a transaction or when statement is prepared through pdo.prepare().
If you pass sequence name as parameter, it should retrieve current session value of sequence.

Warning Calling stmt.lastInsertId(name?) inside a transaction or from a PreparedStatement, will raise an error if value is not defined inside current session.

Note You can always get insert ID through insert returing syntax.

Postgres Prepared Statement

Postgres support prepared statement however, it requires that the statement be prepared only at first execution, which makes it impossible to intercept syntax errors in the query before it is executed.

Prepared Statement require a unique-name for each prepared statement, under the hood this is done automatically by lupdo-postgres through the package uuid-by-string

PostgresDriver Subscribe

PostgresDriver expose two static method to subscribe/unsuscribe notification

const { PostgresDriver } = require('lupdo-postgres');
// ES6 or Typescrypt
import { PostgresDriver } from 'ludpo-postgres';

const testSubscription = message => {
    console.log(message);
};

PostgresDriver.subscribe('test_channel', testSubscription);
PostgresDriver.unsubscribe('test_channel', testSubscription);

message received is of type Notification