{"id":15390211,"url":"https://github.com/gajus/postgres-bridge","last_synced_at":"2025-04-15T21:22:41.898Z","repository":{"id":51227080,"uuid":"520284537","full_name":"gajus/postgres-bridge","owner":"gajus","description":"postgres/pg compatibility layer","archived":false,"fork":false,"pushed_at":"2023-11-30T16:42:43.000Z","size":579,"stargazers_count":29,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-22T04:47:29.704Z","etag":null,"topics":["compatibility","node-postgres","pg","postgres"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gajus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-01T22:57:50.000Z","updated_at":"2024-08-08T19:02:21.000Z","dependencies_parsed_at":"2024-06-19T19:21:26.563Z","dependency_job_id":null,"html_url":"https://github.com/gajus/postgres-bridge","commit_stats":{"total_commits":46,"total_committers":1,"mean_commits":46.0,"dds":0.0,"last_synced_commit":"cdd2a0cd09bb3242bd1f78cc0ca7ade44cb4e2d7"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fpostgres-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fpostgres-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fpostgres-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gajus%2Fpostgres-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gajus","download_url":"https://codeload.github.com/gajus/postgres-bridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249154866,"owners_count":21221487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compatibility","node-postgres","pg","postgres"],"created_at":"2024-10-01T15:04:57.793Z","updated_at":"2025-04-15T21:22:41.881Z","avatar_url":"https://github.com/gajus.png","language":"TypeScript","readme":"# `postgres`/`pg` compatibility layer\n\n[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)\n[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social\u0026label=Follow)](https://twitter.com/kuizinas)\n\nWraps [`postgres`](https://www.npmjs.com/package/postgres) API in a [`pg`](https://www.npmjs.com/package/pg) compatible API.\n\n## Usage\n\n```ts\nimport postgres from 'postgres';\nimport { createPostgresBridge } from 'postgres-bridge';\n\nconst PostgresBridge = createPostgresBridge(postgres);\n\n// pg.Pool Configuration\nconst configuration = {\n  host: 'localhost',\n  user: 'database-user',\n  max: 20,\n  idleTimeoutMillis: 30000,\n  connectionTimeoutMillis: 2000,\n};\n\nconst pool = new PostgresBridge(configuration);\n\nconst connection = await pool.connect();\n\nawait pg.query('SELECT $1::text as name', ['foo']);\n```\n\n## Motivation\n\n`postgres` is leaner/[faster](https://github.com/porsager/postgres-benchmarks) implementation of PostgreSQL protocol in Node.js than `pg`. However, `postgres` API is very different from the more broadly adopted [`pg` client](https://www.npmjs.com/package/pg).\n\nThis 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](https://www.npmjs.com/package/slonik).\n\n## Compatibility\n\n`postgres-bridge` was primarily developed to enable `postgres` use with [Slonik PostgreSQL client](https://www.npmjs.com/package/slonik). However, the scope has since been expanded to support several projects. It is now used in production by a handful real-world applications.\n\nKnown incompatibilities:\n\n* Implicit query pooling is not implemented, i.e. You must use `pool.connect()`\n* `connection.processID` not implemented\n* `pool._pulseQueue` not implemented\n* [callback (CPS) interface](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool#drop-in-backwards-compatible) is not implemented (use promises instead)\n* [providing configuration using environment variables](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool#environment-variables) is not implemented\n* [bring your own promise](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool#bring-your-own-promise) is not implemented\n\nPlease submit PR if you require additional compatibility.\n\n## Benchmark\n\nA basic [benchmark](./test/postgres-bridge/benchmark.ts) shows no overhead as a result of using `postgres-bridge`:\n\n```\npg query: 880ms\npostgres query: 867ms\npostgres-bridge query: 871ms\n```\n\nWhile 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`.\n\n## Development\n\nRunning `postgres-bridge` tests requires having a local PostgreSQL instance.\n\nThe easiest way to setup a temporary instance for testing is using Docker, e.g.\n\n```bash\ndocker run --rm -it -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fpostgres-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgajus%2Fpostgres-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgajus%2Fpostgres-bridge/lists"}