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

postgres-bridge

v1.14.0

Published

pg compatibility layer for postgres.

Downloads

485

Readme

postgres/pg compatibility layer

Canonical Code Style Twitter Follow

Wraps postgres API in a pg compatible API.

Usage

import postgres from 'postgres';
import { createPostgresBridge } from 'postgres-bridge';

const PostgresBridge = createPostgresBridge(postgres);

// pg.Pool Configuration
const configuration = {
  host: 'localhost',
  user: 'database-user',
  max: 20,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
};

const pool = new PostgresBridge(configuration);

const connection = await pool.connect();

await pg.query('SELECT $1::text as name', ['foo']);

Motivation

postgres is leaner/faster implementation of PostgreSQL protocol in Node.js than pg. However, postgres API is very different from the more broadly adopted pg client.

This package allows to adopt postgres without going through a painful migration. In particular, this compatibility layer has been designed to allow adoption of postgres using Slonik PostgreSQL client.

Compatibility

postgres-bridge was primarily developed to enable postgres use with Slonik PostgreSQL client. However, the scope has since been expanded to support several projects. It is now used in production by a handful real-world applications.

Known incompatibilities:

Please submit PR if you require additional compatibility.

Benchmark

A basic benchmark shows no overhead as a result of using postgres-bridge:

pg query: 880ms
postgres query: 867ms
postgres-bridge query: 871ms

While these benchmarks do not show meaningful difference between pg and postgres, in production, in a large codebase, we noticed average response time improve by 30%. It means that in real-world scenarios, postgres overhead is significantly lesser than that of pg.

Development

Running postgres-bridge tests requires having a local PostgreSQL instance.

The easiest way to setup a temporary instance for testing is using Docker, e.g.

docker run --rm -it -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres