8000 feat(postgres): run queries on slonik by colinhacks · Pull Request #121 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Each has examples in [Inference](https://reylo.dev/#inference).

Reylo is bring-your-own-driver. Pass `.run()` a client from any of these, or a Drizzle database over one:

- **Postgres** — `pg`, postgres.js, `Bun.sql`, PGlite, Neon, `pg-promise`, `@vercel/postgres`
- **Postgres** — `pg`, postgres.js, `Bun.sql`, PGlite, Neon, `pg-promise`, `slonik`, `@vercel/postgres`
- **MySQL** — `mysql2`, `mariadb`, PlanetScale, `Bun.sql`
- **SQLite** — `better-sqlite3`, `node:sqlite`, `Bun.sql`, libSQL, Turso, Cloudflare D1 and Durable Objects, `sqlite3`, `sqlite`

Expand Down
1 change: 1 addition & 0 deletions lab/driver-matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Each job runs in its own process: Node 26.7.0 by default, Node 24.19.0 for the s
| @electric-sql/pglite | 0.5.8, 0.4.6, 0.3.16, 0.2.17 | in-process | PGlite, `db.transaction(tx)` |
| @neondatabase/serverless | 1.1.0, 0.10.4, 0.9.5 | Postgres 14 behind a local Neon proxy | Pool, Client, PoolClient, PoolClient inside BEGIN/COMMIT (all over WebSocket), `neon()` over HTTP, `neon(url, { fullResults: true })` |
| pg-promise | 12.7.1 | Postgres 14 (local) | `db`, `db.task(t)`, `db.tx(t)`, nested `t.tx(t2)` (a savepoint) |
| slonik | 49.12.0 | Postgres 14 (local), with Slonik's own type parsers | the pool, a connection from `pool.connect(c)`, `pool.transaction(tx)`, nested `tx.transaction(sp)` (a savepoint) |
| Bun.sql | Bun 1.3.14 | Postgres 14, MySQL 8.4, MySQL 8.0, SQLite file | `sql`, `sql.begin(tx)`, `tx.savepoint(sp)`, `sql.reserve()` (not on SQLite) |
| mysql2 | 3.24.5, 3.15.3, 2.3.3 | MySQL 8.4, MySQL 8.0 | promise Pool, Connection, PoolConnection, PoolConnection inside `beginTransaction()`; callback Pool, Connection and PoolConnection passed without `.promise()` |
| mariadb (a MySQL client) | 3.5.4, 3.4.5, 2.5.6 | MySQL 8.4 | Pool, Connection, PoolConnection, PoolConnection inside `beginTransaction()`; `mariadb/callback` Connection, Pool, and PoolConnection inside `beginTransaction()` |
Expand Down
229 changes: 174 additions & 55 deletions lab/driver-matrix/RESULTS.md

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions lab/driver-matrix/drivers/slonik.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Slonik against the shared local Postgres, with its own type parsers left on: the pool, a
// connection from pool.connect(), a transaction, and a transaction inside it (a savepoint).
import { args, callbackTx, notRun, requireFrom, runJob } from "../lib/harness.ts";

const a = args();
const meta = { pkg: "slonik", version: a.version!, target: "Postgres 14 (local)" };
const url = process.env.DM_PG_URL ?? "postgres://localhost:5432/postgres";

let slonik: any;
try {
slonik = await import(requireFrom.resolve(a.pkg!));
} catch (e) {
notRun(meta, `cannot load ${a.pkg}: ${(e as Error).message}`);
process.exit(0);
}

await runJob(meta, async () => {
const { createPool, sql } = slonik;
const pool = await createPool(url, { maximumPoolSize: 10 });
const begin = (fn: (t: any) => Promise<unknown>) => pool.transaction(fn);
return {
...meta,
dialect: "postgres",
// Slonik's sql tag binds each use of a parameter on its own, so reylo refuses a statement that
// uses one twice, which only a query defined by hand can (tests/execute.test.ts checks it).
skip: { S5a: "a parameter used twice is refused on Slonik", S5b: "a parameter used twice is refused on Slonik" },
count: async (tag) => pool.oneFirst(sql.unsafe`select count(*)::int as n from driver_matrix.scratch where tag = ${tag}`),
shapes: [
{ name: "pool", kind: "async", scope: (fn) => fn(pool) },
{ name: "pool.connect(c)", kind: "async", scope: (fn) => pool.connect((c: any) => fn(c)) },
{
name: "pool.transaction(tx)",
kind: "async",
inTransaction: true,
scope: (fn) => begin((t) => fn(t)),
tx: callbackTx(begin, (t, fn) => t.transaction(fn)),
},
{
name: "tx.transaction(sp) (savepoint)",
kind: "async",
inTransaction: true,
scope: (fn) => begin((t) => t.transaction((sp: any) => fn(sp))),
tx: callbackTx(
(fn) => begin((t) => t.transaction(fn)),
(sp, fn) => sp.transaction(fn),
),
},
],
close: () => pool.end(),
};
});
1 change: 1 addition & 0 deletions lab/driver-matrix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"planetscale-2": "npm:@planetscale/database@2.0.0",
"postgres": "3.4.9",
"postgres-3": "npm:postgres@3.4.9",
"slonik": "49.12.0",
"sqlite": "5.1.1",
"sqlite3-5": "npm:sqlite3@5.1.7",
"sqlite3-6": "npm:sqlite3@6.0.1",
Expand Down
Loading
Loading
0