@shaferllc/keel 0.59.0 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A Keel `Connection` for libSQL / Turso. Pass an `@libsql/client` client (it
3
+ * runs on Node and the edge — Turso speaks HTTP) and register it with dialect
4
+ * `"sqlite"`:
5
+ *
6
+ * import { libsqlConnection } from "@shaferllc/keel/db/libsql";
7
+ * import { setConnection } from "@shaferllc/keel/core";
8
+ * import { createClient } from "@libsql/client";
9
+ *
10
+ * const client = createClient({ url: env.TURSO_URL, authToken: env.TURSO_TOKEN });
11
+ * setConnection(libsqlConnection(client), "sqlite");
12
+ *
13
+ * The client is duck-typed — this module imports no driver, so it never bundles
14
+ * `@libsql/client`.
15
+ */
16
+ /** Build a `Connection` backed by an `@libsql/client` client. */
17
+ export function libsqlConnection(client) {
18
+ return {
19
+ async select(sql, bindings) {
20
+ const { rows } = await client.execute({ sql, args: bindings });
21
+ // Normalize libSQL's Row objects to plain records for casts/serialization.
22
+ return rows.map((row) => ({ ...row }));
23
+ },
24
+ async write(sql, bindings) {
25
+ const { rowsAffected, lastInsertRowid } = await client.execute({ sql, args: bindings });
26
+ return {
27
+ rowsAffected,
28
+ insertId: lastInsertRowid != null ? Number(lastInsertRowid) : undefined,
29
+ };
30
+ },
31
+ };
32
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A Keel `Connection` for Postgres. Pass any node-postgres-compatible client —
3
+ * a `pg` `Pool`/`Client` on Node, or `@neondatabase/serverless` on the edge (both
4
+ * expose the same `query(text, values)` API) — and register it with dialect
5
+ * `"postgres"`:
6
+ *
7
+ * import { pgConnection } from "@shaferllc/keel/db/pg";
8
+ * import { setConnection } from "@shaferllc/keel/core";
9
+ * import { Pool } from "pg"; // or "@neondatabase/serverless"
10
+ *
11
+ * setConnection(pgConnection(new Pool({ connectionString })), "postgres");
12
+ *
13
+ * The client is duck-typed — this module imports no driver, so it works with
14
+ * whichever Postgres client you install and never bundles one.
15
+ *
16
+ * Note on `insertId`: Postgres only returns an inserted row when the statement
17
+ * has a `RETURNING` clause. This adapter surfaces `rows[0].id` when present;
18
+ * otherwise `insertId` is `undefined` (so `insertGetId()` needs a `RETURNING id`).
19
+ */
20
+ import type { Connection, Row } from "../core/database.js";
21
+ /** The slice of the node-postgres client API this adapter uses. */
22
+ export interface PgLike {
23
+ query(text: string, values?: unknown[]): Promise<{
24
+ rows: Row[];
25
+ rowCount: number | null;
26
+ }>;
27
+ }
28
+ /** Build a `Connection` backed by a node-postgres-compatible client. */
29
+ export declare function pgConnection(client: PgLike): Connection;
package/dist/db/pg.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A Keel `Connection` for Postgres. Pass any node-postgres-compatible client —
3
+ * a `pg` `Pool`/`Client` on Node, or `@neondatabase/serverless` on the edge (both
4
+ * expose the same `query(text, values)` API) — and register it with dialect
5
+ * `"postgres"`:
6
+ *
7
+ * import { pgConnection } from "@shaferllc/keel/db/pg";
8
+ * import { setConnection } from "@shaferllc/keel/core";
9
+ * import { Pool } from "pg"; // or "@neondatabase/serverless"
10
+ *
11
+ * setConnection(pgConnection(new Pool({ connectionString })), "postgres");
12
+ *
13
+ * The client is duck-typed — this module imports no driver, so it works with
14
+ * whichever Postgres client you install and never bundles one.
15
+ *
16
+ * Note on `insertId`: Postgres only returns an inserted row when the statement
17
+ * has a `RETURNING` clause. This adapter surfaces `rows[0].id` when present;
18
+ * otherwise `insertId` is `undefined` (so `insertGetId()` needs a `RETURNING id`).
19
+ */
20
+ /** Build a `Connection` backed by a node-postgres-compatible client. */
21
+ export function pgConnection(client) {
22
+ return {
23
+ async select(sql, bindings) {
24
+ const { rows } = await client.query(sql, bindings);
25
+ return rows;
26
+ },
27
+ async write(sql, bindings) {
28
+ const { rows, rowCount } = await client.query(sql, bindings);
29
+ const insertId = rows?.[0]?.id;
30
+ return { rowsAffected: rowCount ?? 0, insertId };
31
+ },
32
+ };
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaferllc/keel",
3
- "version": "0.59.0",
3
+ "version": "0.66.0",
4
4
  "type": "module",
5
5
  "description": "The house framework for Node.js — a service container, providers, routing, JSX views, and a code-generating console.",
6
6
  "license": "MIT",
@@ -28,6 +28,18 @@
28
28
  "./vite": {
29
29
  "types": "./dist/vite/index.d.ts",
30
30
  "import": "./dist/vite/index.js"
31
+ },
32
+ "./db/d1": {
33
+ "types": "./dist/db/d1.d.ts",
34
+ "import": "./dist/db/d1.js"
35
+ },
36
+ "./db/pg": {
37
+ "types": "./dist/db/pg.d.ts",
38
+ "import": "./dist/db/pg.js"
39
+ },
40
+ "./db/libsql": {
41
+ "types": "./dist/db/libsql.d.ts",
42
+ "import": "./dist/db/libsql.js"
31
43
  }
32
44
  },
33
45
  "files": [