@hamur/db 0.0.0-stage → 0.0.1
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.
- package/LICENSE +22 -0
- package/README.md +38 -2
- package/dist/chunks/browser-bun-sql-2yeva2qv.js +53 -0
- package/dist/chunks/browser-bun-sqlite-xxptm4db.js +72 -0
- package/dist/chunks/browser-client-ehmpv0kf.js +130 -0
- package/dist/chunks/browser-d1-a16d23f0.js +8 -0
- package/dist/chunks/browser-index-3t2ajr9m.js +510 -0
- package/dist/chunks/browser-index-kf697bfy.js +113 -0
- package/dist/chunks/browser-index-ppkx8k0t.js +28 -0
- package/dist/chunks/bun-bun-sql-vaz9ggc8.js +54 -0
- package/dist/chunks/bun-bun-sqlite-qcd011rm.js +73 -0
- package/dist/chunks/bun-client-cnt1ddnf.js +131 -0
- package/dist/chunks/bun-d1-d36z1pyr.js +9 -0
- package/dist/chunks/bun-index-06tj00dn.js +11 -0
- package/dist/chunks/bun-index-9na2zkqq.js +224 -0
- package/dist/chunks/bun-index-b47nngck.js +352 -0
- package/dist/chunks/bun-index-hrx1eqma.js +29 -0
- package/dist/chunks/bun-index-pd6k99dv.js +114 -0
- package/dist/src/cli.js +1692 -0
- package/dist/src/devtools.js +153 -0
- package/dist/src/index.js +1491 -0
- package/dist/src/server/index.js +584 -0
- package/dist/src/storage/define.js +7 -0
- package/dist/types/src/build/connections.d.ts +8 -0
- package/dist/types/src/build/databases.d.ts +20 -0
- package/dist/types/src/build/factories.d.ts +6 -0
- package/dist/types/src/build/migrations.d.ts +21 -0
- package/dist/types/src/build/queue.d.ts +7 -0
- package/dist/types/src/build/schema.d.ts +50 -0
- package/dist/types/src/build/tables.d.ts +7 -0
- package/dist/types/src/build/types.d.ts +4 -0
- package/dist/types/src/cli.d.ts +26 -0
- package/dist/types/src/connectors/bun-sql.d.ts +3 -0
- package/dist/types/src/connectors/bun-sqlite.d.ts +3 -0
- package/dist/types/src/connectors/client-fakes.d.ts +57 -0
- package/dist/types/src/connectors/client.d.ts +3 -0
- package/dist/types/src/connectors/d1-fake.d.ts +32 -0
- package/dist/types/src/connectors/d1.d.ts +26 -0
- package/dist/types/src/connectors/node-sqlite.d.ts +3 -0
- package/dist/types/src/connectors/node-test.d.ts +17 -0
- package/dist/types/src/connectors/suite.d.ts +13 -0
- package/dist/types/src/devtools.d.ts +6 -0
- package/dist/types/src/index.d.ts +25 -0
- package/dist/types/src/module.d.ts +6 -0
- package/dist/types/src/options.d.ts +9 -0
- package/dist/types/src/runtime/connector.d.ts +53 -0
- package/dist/types/src/runtime/database.d.ts +15 -0
- package/dist/types/src/runtime/migrate.d.ts +56 -0
- package/dist/types/src/runtime/query.d.ts +12 -0
- package/dist/types/src/runtime/queue-process.d.ts +1 -0
- package/dist/types/src/runtime/queue.d.ts +85 -0
- package/dist/types/src/runtime/registry.d.ts +16 -0
- package/dist/types/src/server/client.d.ts +3 -0
- package/dist/types/src/server/databases.d.ts +4 -0
- package/dist/types/src/server/define-factory.d.ts +9 -0
- package/dist/types/src/server/devtools-routes.d.ts +4 -0
- package/dist/types/src/server/devtools.d.ts +26 -0
- package/dist/types/src/server/door-dev.d.ts +3 -0
- package/dist/types/src/server/door.d.ts +2 -0
- package/dist/types/src/server/factory-core.d.ts +12 -0
- package/dist/types/src/server/factory.d.ts +6 -0
- package/dist/types/src/server/fake.d.ts +35 -0
- package/dist/types/src/server/index.d.ts +12 -0
- package/dist/types/src/server/migrations.d.ts +5 -0
- package/dist/types/src/server/page.d.ts +26 -0
- package/dist/types/src/server/plugin.d.ts +1 -0
- package/dist/types/src/server/queue.d.ts +6 -0
- package/dist/types/src/server/table-entities.d.ts +33 -0
- package/dist/types/src/server/task.d.ts +6 -0
- package/dist/types/src/storage/define.d.ts +12 -0
- package/dist/types/src/storage/driver.d.ts +36 -0
- package/dist/types/src/storage/index.d.ts +3 -0
- package/dist/types/src/types.d.ts +103 -0
- package/package.json +40 -4
- package/src/build/connections.ts +225 -0
- package/src/build/databases.ts +101 -0
- package/src/build/factories.ts +135 -0
- package/src/build/migrations.ts +247 -0
- package/src/build/queue.ts +29 -0
- package/src/build/schema.ts +636 -0
- package/src/build/tables.ts +20 -0
- package/src/build/types.ts +46 -0
- package/src/cli.ts +153 -0
- package/src/connectors/bun-sql.ts +68 -0
- package/src/connectors/bun-sqlite.ts +69 -0
- package/src/connectors/client-fakes.ts +257 -0
- package/src/connectors/client.ts +161 -0
- package/src/connectors/d1-fake.ts +92 -0
- package/src/connectors/d1.ts +151 -0
- package/src/connectors/node-sqlite.ts +83 -0
- package/src/connectors/node-test.ts +31 -0
- package/src/connectors/suite.ts +406 -0
- package/src/devtools.ts +264 -0
- package/src/env.d.ts +28 -0
- package/src/index.ts +46 -0
- package/src/module.ts +36 -0
- package/src/options.ts +104 -0
- package/src/runtime/connector.ts +87 -0
- package/src/runtime/database.ts +353 -0
- package/src/runtime/migrate.ts +307 -0
- package/src/runtime/query.ts +82 -0
- package/src/runtime/queue-process.ts +39 -0
- package/src/runtime/queue.ts +380 -0
- package/src/runtime/registry.ts +61 -0
- package/src/server/client.ts +6 -0
- package/src/server/databases.ts +24 -0
- package/src/server/define-factory.ts +22 -0
- package/src/server/devtools-routes.ts +34 -0
- package/src/server/devtools.ts +205 -0
- package/src/server/door-dev.ts +6 -0
- package/src/server/door.ts +4 -0
- package/src/server/factory-core.ts +91 -0
- package/src/server/factory.ts +19 -0
- package/src/server/fake.ts +348 -0
- package/src/server/index.ts +17 -0
- package/src/server/migrations.ts +26 -0
- package/src/server/page.ts +181 -0
- package/src/server/plugin.ts +14 -0
- package/src/server/queue.ts +38 -0
- package/src/server/table-entities.ts +29 -0
- package/src/server/task.ts +15 -0
- package/src/storage/define.ts +12 -0
- package/src/storage/driver.ts +419 -0
- package/src/storage/index.ts +7 -0
- package/src/types.ts +101 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 productdevbook
|
|
4
|
+
Copyright (c) 2019 Material-UI SAS
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hamur/db
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The first-party database module for [Hamur](https://github.com/productdevbook/hamur), a full-stack web framework for Bun. SQL through one small API, `useDatabase()` with a tagged `sql` whose every value is a bound parameter, on `Bun.SQL` (Postgres, MySQL, SQLite), `bun:sqlite`, `node:sqlite` and Cloudflare D1. No query builder. It has no dependency.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @hamur/db
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Add it to `modules` in `hamur.config.ts` and set the `db` key:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig, env } from "hamur"
|
|
15
|
+
import db from "@hamur/db"
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
modules: [db],
|
|
19
|
+
db: { connections: { default: { connector: "bun-sql", url: env("DATABASE_URL") } } },
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`DATABASE_URL` is declared in `app/env.ts` (`defineEnv({ DATABASE_URL: {} })`) and read when the server starts.
|
|
24
|
+
|
|
25
|
+
## Example
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { defineHandler } from "hamur/server"
|
|
29
|
+
import { useDatabase } from "@hamur/db/server"
|
|
30
|
+
|
|
31
|
+
export const listTodos = defineHandler({
|
|
32
|
+
method: "GET",
|
|
33
|
+
handler: () => useDatabase().sql`select * from todos where done = ${0} order by id`,
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Docs
|
|
38
|
+
|
|
39
|
+
[Documentation](https://docs.productdevbook.com/) and the [API reference](https://docs.productdevbook.com/api-reference/db). MIT license.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
insertId
|
|
3
|
+
} from "./browser-index-ppkx8k0t.js";
|
|
4
|
+
|
|
5
|
+
// packages/db/src/connectors/bun-sql.ts
|
|
6
|
+
var ADAPTER = { postgres: "postgres", mysql: "mysql", mariadb: "mysql", sqlite: "sqlite" };
|
|
7
|
+
async function openBunSql({ name, dialect, url }) {
|
|
8
|
+
const sql = url === undefined ? new Bun.SQL : new Bun.SQL(url);
|
|
9
|
+
const adapter = String(sql.options.adapter ?? "postgres");
|
|
10
|
+
if (ADAPTER[adapter] !== dialect) {
|
|
11
|
+
await sql.close();
|
|
12
|
+
throw new Error(`db.connections.${name} is dialect ${dialect} but its url is ${adapter}:; set db.connections.${name}.dialect`);
|
|
13
|
+
}
|
|
14
|
+
const sessionOf = (client) => {
|
|
15
|
+
const bind = (params) => dialect === "postgres" ? params.map((value) => Array.isArray(value) ? client.array(value) : value) : params;
|
|
16
|
+
return {
|
|
17
|
+
all: async (text, params) => [...await client.unsafe(text, bind(params))],
|
|
18
|
+
async run(text, params) {
|
|
19
|
+
const result = await client.unsafe(text, bind(params));
|
|
20
|
+
const id = dialect === "postgres" ? undefined : insertId(result.lastInsertRowid);
|
|
21
|
+
return id === undefined ? { changes: result.affectedRows } : { changes: result.affectedRows, lastInsertId: id };
|
|
22
|
+
},
|
|
23
|
+
async exec(text) {
|
|
24
|
+
await client.unsafe(text).simple();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const reservedOf = (client) => ({
|
|
29
|
+
...sessionOf(client),
|
|
30
|
+
transaction: (fn) => dialect === "sqlite" ? client.begin("immediate", (tx) => fn(sessionOf(tx))) : client.begin((tx) => fn(sessionOf(tx)))
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
...sessionOf(sql),
|
|
34
|
+
async reserve(fn) {
|
|
35
|
+
if (dialect === "sqlite")
|
|
36
|
+
return fn(reservedOf(sql));
|
|
37
|
+
const reserved = await sql.reserve();
|
|
38
|
+
try {
|
|
39
|
+
return await fn(reservedOf(reserved));
|
|
40
|
+
} finally {
|
|
41
|
+
await reserved.release();
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
transaction: (fn) => sql.begin((tx) => fn({
|
|
45
|
+
...sessionOf(tx),
|
|
46
|
+
savepoint: (inner) => tx.savepoint("batch", (point) => inner(sessionOf(point)))
|
|
47
|
+
})),
|
|
48
|
+
close: () => sql.close()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
openBunSql as default
|
|
53
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUSY_TIMEOUT,
|
|
3
|
+
journalWal,
|
|
4
|
+
insertId
|
|
5
|
+
} from "./browser-index-ppkx8k0t.js";
|
|
6
|
+
|
|
7
|
+
// packages/db/src/connectors/bun-sqlite.ts
|
|
8
|
+
import { Database as SQLite } from "bun:sqlite";
|
|
9
|
+
import { mkdirSync } from "node:fs";
|
|
10
|
+
import { dirname, resolve } from "node:path";
|
|
11
|
+
function openBunSqlite({ path }) {
|
|
12
|
+
if (!path)
|
|
13
|
+
throw new TypeError("The bun-sqlite connector needs a path");
|
|
14
|
+
const memory = path === ":memory:";
|
|
15
|
+
const file = memory ? path : resolve(path);
|
|
16
|
+
if (!memory)
|
|
17
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
18
|
+
const db = new SQLite(file, { create: true, strict: true });
|
|
19
|
+
db.run(`PRAGMA busy_timeout = ${BUSY_TIMEOUT}`);
|
|
20
|
+
if (!memory)
|
|
21
|
+
journalWal((text) => db.run(text));
|
|
22
|
+
const bindings = (params) => params;
|
|
23
|
+
const session = {
|
|
24
|
+
all: async (text, params) => db.query(text).all(...bindings(params)),
|
|
25
|
+
async run(text, params) {
|
|
26
|
+
const result = db.query(text).run(...bindings(params));
|
|
27
|
+
const id = insertId(result.lastInsertRowid);
|
|
28
|
+
return id === undefined ? { changes: result.changes } : { changes: result.changes, lastInsertId: id };
|
|
29
|
+
},
|
|
30
|
+
async exec(text) {
|
|
31
|
+
db.run(text);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const inTransaction = {
|
|
35
|
+
...session,
|
|
36
|
+
async savepoint(fn) {
|
|
37
|
+
db.run("SAVEPOINT hamur_batch");
|
|
38
|
+
try {
|
|
39
|
+
const result = await fn(session);
|
|
40
|
+
db.run("RELEASE SAVEPOINT hamur_batch");
|
|
41
|
+
return result;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
db.run("ROLLBACK TO SAVEPOINT hamur_batch");
|
|
44
|
+
db.run("RELEASE SAVEPOINT hamur_batch");
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const transaction = async (fn) => {
|
|
50
|
+
db.run("BEGIN IMMEDIATE");
|
|
51
|
+
try {
|
|
52
|
+
const result = await fn(inTransaction);
|
|
53
|
+
db.run("COMMIT");
|
|
54
|
+
return result;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (db.inTransaction)
|
|
57
|
+
db.run("ROLLBACK");
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
...session,
|
|
63
|
+
transaction,
|
|
64
|
+
reserve: (fn) => fn({ ...session, transaction }),
|
|
65
|
+
async close() {
|
|
66
|
+
db.close();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
openBunSqlite as default
|
|
72
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mysqlStatements
|
|
3
|
+
} from "./browser-index-3t2ajr9m.js";
|
|
4
|
+
import {
|
|
5
|
+
sqliteStatements2
|
|
6
|
+
} from "./browser-index-kf697bfy.js";
|
|
7
|
+
import {
|
|
8
|
+
insertId
|
|
9
|
+
} from "./browser-index-ppkx8k0t.js";
|
|
10
|
+
|
|
11
|
+
// packages/db/src/connectors/client.ts
|
|
12
|
+
var BEGIN = { postgres: "BEGIN", mysql: "START TRANSACTION", sqlite: "BEGIN IMMEDIATE" };
|
|
13
|
+
var refused = new WeakMap;
|
|
14
|
+
function statementsOf(dialect, text) {
|
|
15
|
+
if (dialect === "mysql")
|
|
16
|
+
return mysqlStatements(text);
|
|
17
|
+
if (dialect === "sqlite")
|
|
18
|
+
return sqliteStatements2(text);
|
|
19
|
+
return [text];
|
|
20
|
+
}
|
|
21
|
+
function after(error, cause) {
|
|
22
|
+
if (error instanceof Error && error.cause === undefined)
|
|
23
|
+
error.cause = cause;
|
|
24
|
+
return error;
|
|
25
|
+
}
|
|
26
|
+
var asError = (value) => value instanceof Error ? value : new Error(String(value));
|
|
27
|
+
async function openClient({ name, dialect, client: load }) {
|
|
28
|
+
if (!load)
|
|
29
|
+
throw new TypeError("The client connector needs a client file");
|
|
30
|
+
const at = `db.connections.${name}`;
|
|
31
|
+
const known = refused.get(load);
|
|
32
|
+
if (known)
|
|
33
|
+
throw known;
|
|
34
|
+
const factory = (await load()).default;
|
|
35
|
+
if (typeof factory !== "function")
|
|
36
|
+
throw new TypeError(`The database client of ${at} must export default defineDatabaseClient(() => client)`);
|
|
37
|
+
const client = await factory();
|
|
38
|
+
if (typeof client !== "object" || client === null || typeof client.query !== "function") {
|
|
39
|
+
const error = new TypeError(`The database client of ${at} has no query(text, params); return { query, reserve?, end? } from defineDatabaseClient`);
|
|
40
|
+
refused.set(load, error);
|
|
41
|
+
await client?.end?.().catch(() => {});
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
const call = async (query, text, params) => {
|
|
45
|
+
const result = await query(text, params);
|
|
46
|
+
if (typeof result !== "object" || result === null || !Array.isArray(result.rows)) {
|
|
47
|
+
throw new TypeError(`The database client of ${at} returned no rows array from query(); return { rows, changes?, lastInsertId? }`);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const send = async (query, text) => void await query(text, []);
|
|
52
|
+
const sessionOf = (query) => ({
|
|
53
|
+
all: async (text, params) => (await call(query, text, params)).rows,
|
|
54
|
+
async run(text, params) {
|
|
55
|
+
const result = await call(query, text, params);
|
|
56
|
+
const changes = result.changes ?? 0;
|
|
57
|
+
const id = dialect === "postgres" ? undefined : insertId(result.lastInsertId);
|
|
58
|
+
return id === undefined ? { changes } : { changes, lastInsertId: id };
|
|
59
|
+
},
|
|
60
|
+
async exec(text) {
|
|
61
|
+
for (const statement of statementsOf(dialect, text))
|
|
62
|
+
await send(query, statement);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const reserved = async (needs, fn) => {
|
|
66
|
+
if (typeof client.reserve !== "function")
|
|
67
|
+
throw new Error(`${needs} a client with reserve(); the client of ${at} has none`);
|
|
68
|
+
const connection = await client.reserve();
|
|
69
|
+
let bad;
|
|
70
|
+
let result;
|
|
71
|
+
try {
|
|
72
|
+
result = await fn(connection.query.bind(connection), (error) => void (bad ??= asError(error)));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
try {
|
|
75
|
+
await connection.release(bad);
|
|
76
|
+
} catch (released) {
|
|
77
|
+
throw after(released, error);
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
await connection.release(bad);
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
const inTransaction = async (query, broken, fn) => {
|
|
85
|
+
await send(query, BEGIN[dialect]);
|
|
86
|
+
try {
|
|
87
|
+
const result = await fn();
|
|
88
|
+
await send(query, "COMMIT");
|
|
89
|
+
return result;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
await send(query, "ROLLBACK").catch((failed) => broken(after(failed, error)));
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const savepoint = (query) => async (fn) => {
|
|
96
|
+
await send(query, "SAVEPOINT hamur_batch");
|
|
97
|
+
try {
|
|
98
|
+
const result = await fn(sessionOf(query));
|
|
99
|
+
await send(query, "RELEASE SAVEPOINT hamur_batch");
|
|
100
|
+
return result;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
try {
|
|
103
|
+
await send(query, "ROLLBACK TO SAVEPOINT hamur_batch");
|
|
104
|
+
await send(query, "RELEASE SAVEPOINT hamur_batch");
|
|
105
|
+
} catch (failed) {
|
|
106
|
+
throw after(failed, error);
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
...sessionOf(client.query.bind(client)),
|
|
113
|
+
transaction: (fn) => reserved("transaction needs", (query, broken) => inTransaction(query, broken, () => fn({ ...sessionOf(query), savepoint: savepoint(query) }))),
|
|
114
|
+
reserve: (fn) => reserved("migrations need", async (query, broken) => {
|
|
115
|
+
const session = sessionOf(query);
|
|
116
|
+
try {
|
|
117
|
+
return await fn({ ...session, transaction: (inner) => inTransaction(query, broken, () => inner(session)) });
|
|
118
|
+
} catch (error) {
|
|
119
|
+
broken(error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}),
|
|
123
|
+
async close() {
|
|
124
|
+
await client.end?.();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
openClient as default
|
|
130
|
+
};
|