2025-01-07 23:03:44 +11:00
# pglue
2025-01-10 19:53:04 +11:00
The glue for TypeScript to PostgreSQL.
2025-01-07 23:03:44 +11:00
2025-01-10 19:53:04 +11:00
## Overview
2025-01-10 19:56:16 +11:00
- 🌟 [High performance ](#benchmarks ), fully asynchronous, written in modern TypeScript
2025-01-10 19:53:04 +11:00
- 🐢 First class Deno support
- 💬 Automatic query parameterisation
- 🌧️ Automatic query pipelining
2025-01-10 19:56:16 +11:00
- 📣 Listen/notify support
2025-01-10 19:53:04 +11:00
- 📤 Connection pool support
2025-01-10 20:32:06 +11:00
## Installation
```ts
2025-01-12 01:09:34 +11:00
import pglue from "https://git.lua.re/luaneko/pglue/raw/tag/v0.2.0/mod.ts";
2025-01-10 20:35:32 +11:00
// ...or from github:
2025-01-12 01:09:34 +11:00
import pglue from "https://raw.githubusercontent.com/luaneko/pglue/refs/tags/v0.2.0/mod.ts";
2025-01-10 20:32:06 +11:00
```
2025-01-10 19:53:04 +11:00
## Documentation
TODO: Write the documentation in more detail here.
2025-01-07 23:03:44 +11:00
## Benchmarks
2025-01-12 00:26:38 +11:00
Performance is generally on par with [postgres.js][1] and up to **5x faster** than [deno-postgres][2]. Keep in mind that database driver benchmarks are largely dependent on the database performance itself and does not necessarily represent accurate real-world performance.
2025-01-07 23:03:44 +11:00
2025-01-10 19:56:16 +11:00
Tested on a 4 core, 2800 MHz, x86_64-pc-linux-gnu, QEMU VM, with Deno 2.1.4 and PostgreSQL 17.1 on localhost:
2025-01-07 23:03:44 +11:00
2025-01-10 19:56:16 +11:00
Query `select * from pg_type` :
2025-01-10 19:32:41 +11:00
2025-01-12 00:26:38 +11:00
```
2025-01-07 23:03:44 +11:00
CPU | Common KVM Processor v2.0
Runtime | Deno 2.1.4 (x86_64-unknown-linux-gnu)
benchmark time/iter (avg) iter/s (min … max) p75 p99 p995
--------------- ----------------------------- --------------------- --------------------------
group select n=1
2025-01-12 00:26:38 +11:00
pglue 8.8 ms 113.8 ( 7.2 ms … 11.8 ms) 9.7 ms 11.8 ms 11.8 ms
postgres.js 10.8 ms 92.3 ( 8.1 ms … 22.0 ms) 11.2 ms 22.0 ms 22.0 ms
deno-postgres 38.9 ms 25.7 ( 23.5 ms … 51.9 ms) 40.3 ms 51.9 ms 51.9 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
1.23x faster than postgres.js
4.42x faster than deno-postgres
2025-01-07 23:03:44 +11:00
group select n=5
2025-01-12 00:26:38 +11:00
pglue 40.1 ms 25.0 ( 36.1 ms … 48.2 ms) 40.7 ms 48.2 ms 48.2 ms
postgres.js 48.7 ms 20.5 ( 38.9 ms … 61.2 ms) 52.7 ms 61.2 ms 61.2 ms
deno-postgres 184.7 ms 5.4 (166.5 ms … 209.5 ms) 190.7 ms 209.5 ms 209.5 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
1.22x faster than postgres.js
4.61x faster than deno-postgres
2025-01-07 23:03:44 +11:00
group select n=10
2025-01-12 00:26:38 +11:00
pglue 80.7 ms 12.4 ( 73.5 ms … 95.4 ms) 82.2 ms 95.4 ms 95.4 ms
postgres.js 89.1 ms 11.2 ( 82.5 ms … 101.7 ms) 94.4 ms 101.7 ms 101.7 ms
deno-postgres 375.3 ms 2.7 (327.4 ms … 393.9 ms) 390.7 ms 393.9 ms 393.9 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
1.10x faster than postgres.js
4.65x faster than deno-postgres
2025-01-10 19:32:41 +11:00
```
2025-01-07 23:03:44 +11:00
2025-01-10 19:56:16 +11:00
Query `insert into my_table (a, b, c) values (${a}, ${b}, ${c})` :
2025-01-10 19:32:41 +11:00
2025-01-12 00:26:38 +11:00
```
2025-01-07 23:03:44 +11:00
group insert n=1
2025-01-12 00:26:38 +11:00
pglue 259.2 µs 3,858 (165.4 µs … 2.8 ms) 258.0 µs 775.4 µs 2.8 ms
postgres.js 235.9 µs 4,239 (148.8 µs … 1.2 ms) 250.3 µs 577.4 µs 585.6 µs
deno-postgres 306.7 µs 3,260 (198.8 µs … 1.3 ms) 325.9 µs 1.0 ms 1.3 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
1.10x slower than postgres.js
1.18x faster than deno-postgres
2025-01-07 23:03:44 +11:00
group insert n=10
2025-01-12 00:26:38 +11:00
pglue 789.7 µs 1,266 (553.2 µs … 2.7 ms) 783.4 µs 2.4 ms 2.7 ms
postgres.js 755.6 µs 1,323 (500.5 µs … 3.4 ms) 795.0 µs 2.8 ms 3.4 ms
deno-postgres 2.2 ms 458.1 ( 1.6 ms … 5.2 ms) 2.3 ms 4.8 ms 5.2 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
1.04x slower than postgres.js
2.76x faster than deno-postgres
2025-01-07 23:03:44 +11:00
group insert n=100
2025-01-12 00:26:38 +11:00
pglue 5.8 ms 172.0 ( 3.2 ms … 9.9 ms) 6.8 ms 9.9 ms 9.9 ms
postgres.js 13.0 ms 76.8 ( 8.6 ms … 20.8 ms) 15.4 ms 20.8 ms 20.8 ms
deno-postgres 18.5 ms 54.1 ( 14.3 ms … 32.1 ms) 20.0 ms 32.1 ms 32.1 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
2.24x faster than postgres.js
3.18x faster than deno-postgres
2025-01-07 23:03:44 +11:00
group insert n=200
2025-01-12 00:26:38 +11:00
pglue 8.8 ms 113.4 ( 6.0 ms … 14.1 ms) 10.0 ms 14.1 ms 14.1 ms
postgres.js 28.2 ms 35.5 ( 21.1 ms … 47.0 ms) 29.6 ms 47.0 ms 47.0 ms
deno-postgres 37.0 ms 27.0 ( 32.0 ms … 48.1 ms) 39.4 ms 48.1 ms 48.1 ms
2025-01-07 23:03:44 +11:00
summary
pglue
2025-01-12 00:26:38 +11:00
3.20x faster than postgres.js
4.20x faster than deno-postgres
2025-01-07 23:03:44 +11:00
```
[1]: https://github.com/porsager/postgres
[2]: https://github.com/denodrivers/postgres