Wraps postgres API in a pg compatible API.

Overview

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
You might also like...

Ferramenta desenvolvida para migrar dados de um banco de dados Sqlite para Postgres.

Ferramenta desenvolvida para migrar dados de um banco de dados Sqlite para Postgres.

Sqlite to Postgres Migration Ferramenta desenvolvida para migrar dados de um banco de dados Sqlite para Postgres. Atualmente vocรช pode: Pegar os dados

Dec 15, 2022

100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

โš ๏ธ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

Dec 29, 2022

Fastest way to get financial data from Plaid into your Postgres database. Go from zero to live in 5 minutes without a single line of code.

Fastest way to get financial data from Plaid into your Postgres database. Go from zero to live in 5 minutes without a single line of code.

Venice Venice is a the fastest way to get financial data from Plaid into your Postgres database. Zero to production in 5 minutes without a single line

Dec 12, 2022

A demo of using RSC and Vercel Postgres, legally

A demo of using RSC and Vercel Postgres, legally

How is this not illegal This beautiful tweet by Dan Abramov brought to life. Setting it up Create a Vercel Postgres database and link it to your proje

Aug 14, 2023

Generate type definitions compatible with @kintone/rest-api-client

Generate type definitions compatible with @kintone/rest-api-client

kintone-form-model-generator Generate type definitions compatible with @kintone/rest-api-client Prerequirements Node.js (=12) Install # Install npm i

Dec 15, 2022

Quikly scaffold a postman collection for a GraphQL API. Compatible with Insomnia.

Quikly scaffold a postman collection for a GraphQL API. Compatible with Insomnia.

GraphMan Quickly scaffold a postman collection for a GraphQL API. GraphMan CLI generates an complete collection from a GraphQL endpoint, containing on

Dec 28, 2022

Zepto.js is a minimalist JavaScript library for modern browsers, with a jQuery-compatible API

Zepto.js โ€“ a minimalist JavaScript library Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API. If you u

Dec 31, 2022

A Fetch API-compatible PlanetScale database driver

PlanetScale Serverless Driver for JavaScript A Fetch API-compatible PlanetScale database driver for serverless and edge compute platforms that require

Dec 27, 2022

๐Ÿ“ A multiselect component in Pure JS - Compatible with IE11

๐Ÿ“ A multiselect component in Pure JS - Compatible with IE11

Iconic Multiselect A multiselect component written in pure JavaScript - Also compatible with IE11 Default template: Custom template: ๐Ÿš€ Try live demo

Aug 31, 2022
Comments
  • type parsers

    type parsers

    The challenge is that pg accepts a function that resolves types at runtime, e.g.

    types: {
      getTypeParser: (oid: number) => {
        if (oid !== NUMERIC_OID) {
          throw new Error('Unexpected OID.');
        }
    
        return (value: string) => {
          return Number.parseFloat(value);
        };
      },
    },
    

    Meanwhile, postgres accepts a statically typed list, e.g.

    types: [
      {
        from: [
          NUMERIC_OID,
        ],
        parse: (value: string) => {
          return Number.parseFloat(value);
        },
      },
    ],
    
    incompatibility 
    opened by gajus 2
  • The automated release is failing ๐Ÿšจ

    The automated release is failing ๐Ÿšจ

    :rotating_light: The automated release from the main branch failed. :rotating_light:

    I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

    You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iโ€™m sure you can fix this ๐Ÿ’ช.

    Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

    Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

    If you are not sure how to resolve this, here are some links that can help you:

    If those donโ€™t help, or if this issue is reporting something you think isnโ€™t right, you can always ask the humans behind semantic-release.


    No npm token specified.

    An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

    Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


    Good luck with your project โœจ

    Your semantic-release bot :package::rocket:

    semantic-release 
    opened by github-actions[bot] 0
  • Slonik doesn't seem to respect pool settings

    Slonik doesn't seem to respect pool settings

    Regardless of my client config in slonik, it seems to always check a new client out with the message: created a new client connection. Also, how do I set minimum connections with this bridge?

    opened by jetaggart 0
Owner
Gajus Kuizinas
Software architect. Passionate about JavaScript, React, GraphQL, Redux. Active open-source contributor.
Gajus Kuizinas
My-portfolio - Built with Namecheap, Digital Ocean, Nginx, PM2, SSL, NextJs, Tailwind 3, Graphql, NexusJS, Prisma, Postgres, Passion and Love

Current Implementation technologies Nextjs with Typescript. Static pages/ Server side rendering. Easy peasy state management (Might not need it with i

Samrood Ali 1 Jan 10, 2022
A Turborepo with Strapi v4 (w/ postgres database) + Next.js powered by docker and docker-compose

Turborepo + Strapi + Next.js + Docker A Turborepo with Strapi v4 (w/ postgres database) + Next.js powered by docker and docker-compose. โš ๏ธ Prerequisit

Elvin Chu 60 Dec 29, 2022
A complete template for 2022 focused on around React, Postgres and various web3 integrations.

A complete template for 2022 focused on around React, Postgres and various web3 integrations. You can use the template to make a website, a web application, a hybrid decentralized web application, or even a DAO.

jim 45 Dec 22, 2022
Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Khalid Abuhakmeh 5 Feb 16, 2022
Simple "everyday CRUD" Postgres queries with perfect TypeScript types

Crudely Typed Simple "everyday CRUD" Postgres queries with perfect TypeScript types. Zero dependencies. Designed to work with pg-to-ts and node-postgr

Dan Vanderkam 26 Dec 26, 2022
Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno

?? Fastest full-featured node & deno client ?? ES6 Tagged Template Strings at the core ??โ€โ™€๏ธ Simple surface API ??๏ธ Dynamic query support ?? Chat and

Rasmus Porsager 4.3k Jan 1, 2023
The Complete Intro to Postgres, as taught by Brian Holt for Frontend Masters

next-course-starter A NextJS starter to get you started creating educational materials using Markdown Get Started Set up Node.js v14+ Clone this repo

Brian Holt 107 Dec 30, 2022
Connect to a Postgres database from a Cloudflare Worker, using Cloudflare Tunnel

Cloudflare Workers Postgres Client This is an experimental module. Heavily based on cloudflare/worker-template-postgres, but cleaned up and bundled in

BubblyDoo 17 Dec 22, 2022
Integration with https://neon.tech Serverless Postgres

README Welcome to RedwoodJS! Prerequisites Redwood requires Node.js (>=14.19.x <=16.x) and Yarn (>=1.15) Are you on Windows? For best results, follow

RedwoodJS 3 Sep 16, 2022
๐Ÿ˜ instantly stand up full Postgres databases in your AVA tests

ava-postgres ava-postgres is a test fixture for AVA that provides you with nearly-instant access to a fresh Postgres database for every test. Installa

Seam 2 Dec 22, 2022