@hamur/db 0.0.0-stage → 0.0.2
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 +55 -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
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test"
|
|
2
|
+
import { createSqlFragment } from "hamur/server/internal"
|
|
3
|
+
import { createDatabase } from "../runtime/database.ts"
|
|
4
|
+
import type { Connector } from "../runtime/connector.ts"
|
|
5
|
+
import type { Database, Dialect } from "../types.ts"
|
|
6
|
+
|
|
7
|
+
const KEY: Record<Dialect, string> = {
|
|
8
|
+
sqlite: "integer primary key",
|
|
9
|
+
postgres: "serial primary key",
|
|
10
|
+
mysql: "int auto_increment primary key",
|
|
11
|
+
}
|
|
12
|
+
const BYTES: Record<Dialect, string> = { sqlite: "blob", postgres: "bytea", mysql: "blob" }
|
|
13
|
+
const FLAG: Record<Dialect, string> = { sqlite: "integer", postgres: "boolean", mysql: "tinyint" }
|
|
14
|
+
const TIME: Record<Dialect, string> = { sqlite: "text", postgres: "timestamptz", mysql: "datetime(3)" }
|
|
15
|
+
const INJECTION = "'; DROP TABLE hamur_suite; --"
|
|
16
|
+
|
|
17
|
+
const TRANSACTION_REFUSED =
|
|
18
|
+
"transaction is not available on the d1 connector: D1 has no interactive transactions; use batch([...])"
|
|
19
|
+
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
|
|
20
|
+
|
|
21
|
+
export interface SuiteOptions {
|
|
22
|
+
/** The reason the suite is skipped (a missing server URL). */
|
|
23
|
+
skip?: string
|
|
24
|
+
/** `false` when the connector refuses `transaction` (d1). */
|
|
25
|
+
transactions?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The connector suite. `open` makes a fresh connector on an empty database each time it is called; the suite owns the table
|
|
30
|
+
* `hamur_suite` and drops it at the end.
|
|
31
|
+
*/
|
|
32
|
+
export function connectorSuite(
|
|
33
|
+
label: string,
|
|
34
|
+
dialect: Dialect,
|
|
35
|
+
open: () => Connector | Promise<Connector>,
|
|
36
|
+
{ skip, transactions = true }: SuiteOptions = {},
|
|
37
|
+
): void {
|
|
38
|
+
describe.skipIf(skip !== undefined)(`${label} connector${skip ? ` (skipped: ${skip})` : ""}`, () => {
|
|
39
|
+
let db: Database
|
|
40
|
+
let other: Database
|
|
41
|
+
|
|
42
|
+
beforeAll(async () => {
|
|
43
|
+
db = createDatabase("default", dialect, open)
|
|
44
|
+
other = createDatabase("analytics", dialect, open)
|
|
45
|
+
await db.exec("drop table if exists hamur_suite")
|
|
46
|
+
await db.exec(
|
|
47
|
+
`create table hamur_suite (id ${KEY[dialect]}, v text not null, flag ${FLAG[dialect]}, at ${TIME[dialect]}, data ${BYTES[dialect]}, big bigint)`,
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
afterAll(async () => {
|
|
52
|
+
await db.exec("drop table if exists hamur_suite").catch(() => {})
|
|
53
|
+
await db.close()
|
|
54
|
+
await other.close()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const values = async () => (await db.sql<{ v: string }>`select v from hamur_suite order by id`).map((row) => row.v)
|
|
58
|
+
const clear = () => db.run`delete from hamur_suite`
|
|
59
|
+
|
|
60
|
+
test("a value is bound, never text: an injection attempt is stored and read back literally", async () => {
|
|
61
|
+
await clear()
|
|
62
|
+
await db.run`insert into hamur_suite (v) values (${INJECTION})`
|
|
63
|
+
expect(await values()).toEqual([INJECTION])
|
|
64
|
+
const found = await db.first<{ v: string }>`select v from hamur_suite where v = ${INJECTION}`
|
|
65
|
+
expect(found?.v).toBe(INJECTION)
|
|
66
|
+
expect(await db.sql`select v from hamur_suite where v = ${"x' or '1'='1"}`).toEqual([])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test("text and values carry the dialect's placeholders and the values in order", () => {
|
|
70
|
+
const query = db.sql`select v from hamur_suite where v = ${"a"} and id > ${1}`
|
|
71
|
+
expect(query.text).toBe(
|
|
72
|
+
dialect === "postgres"
|
|
73
|
+
? "select v from hamur_suite where v = $1 and id > $2"
|
|
74
|
+
: "select v from hamur_suite where v = ? and id > ?",
|
|
75
|
+
)
|
|
76
|
+
expect(query.values).toEqual(["a", 1])
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test("a SqlFragment is spliced at its place and its values bound there, in sql, first and run", async () => {
|
|
80
|
+
await clear()
|
|
81
|
+
const mark = (dialect: Dialect, index: number) => (dialect === "postgres" ? `$${index}` : "?")
|
|
82
|
+
const either = createSqlFragment((dialect, firstIndex) => ({
|
|
83
|
+
text: `(v = ${mark(dialect, firstIndex)} or v = ${mark(dialect, firstIndex + 1)})`,
|
|
84
|
+
values: [INJECTION, "b"],
|
|
85
|
+
}))
|
|
86
|
+
const insert = db.run`insert into hamur_suite (v) values (${INJECTION}), (${"b"}), (${"c"})`
|
|
87
|
+
expect((await insert).changes).toBe(3)
|
|
88
|
+
const query = db.sql<{
|
|
89
|
+
v: string
|
|
90
|
+
}>`select v from hamur_suite where id > ${0} and ${either} and v <> ${"c"} order by id`
|
|
91
|
+
expect(query.text).toBe(
|
|
92
|
+
`select v from hamur_suite where id > ${mark(dialect, 1)} and (v = ${mark(dialect, 2)} or v = ${mark(dialect, 3)}) and v <> ${mark(dialect, 4)} order by id`,
|
|
93
|
+
)
|
|
94
|
+
expect(query.values).toEqual([0, INJECTION, "b", "c"])
|
|
95
|
+
expect((await query).map((row) => row.v)).toEqual([INJECTION, "b"])
|
|
96
|
+
expect(await db.first<{ v: string }>`select v from hamur_suite where ${either} and v = ${"b"}`).toEqual({
|
|
97
|
+
v: "b",
|
|
98
|
+
})
|
|
99
|
+
expect((await db.run`update hamur_suite set v = ${"z"} where ${either}`).changes).toBe(2)
|
|
100
|
+
expect(await values()).toEqual(["z", "z", "c"])
|
|
101
|
+
const other = dialect === "postgres" ? "sqlite" : "postgres"
|
|
102
|
+
const foreign = createSqlFragment(() => ({ text: "(1 = 1)", values: [] }), other)
|
|
103
|
+
expect(() => db.sql`select v from hamur_suite where v = ${"a"} and ${foreign}`).toThrow(
|
|
104
|
+
new TypeError(`db.sql value 2 is a SqlFragment made for ${other}; this connection "default" is ${dialect}`),
|
|
105
|
+
)
|
|
106
|
+
const forged = { [Symbol("sqlFragment")]: () => ({ text: "(1 = 1)", values: [] }) }
|
|
107
|
+
expect(() => db.run`delete from hamur_suite where ${forged as never}`).toThrow(
|
|
108
|
+
new TypeError("db.run value 1 is an object; bind JSON.stringify(value) for a json column"),
|
|
109
|
+
)
|
|
110
|
+
expect(await values()).toEqual(["z", "z", "c"])
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test("a query is lazy and runs once", async () => {
|
|
114
|
+
await clear()
|
|
115
|
+
const insert = db.run`insert into hamur_suite (v) values (${"once"})`
|
|
116
|
+
await sleep(5)
|
|
117
|
+
expect(await values()).toEqual([])
|
|
118
|
+
const [first, second] = [await insert, await insert]
|
|
119
|
+
expect(first).toBe(second)
|
|
120
|
+
expect(await values()).toEqual(["once"])
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test("sql returns rows, first the first row or undefined, run the rows written", async () => {
|
|
124
|
+
await clear()
|
|
125
|
+
const inserted = await db.run`insert into hamur_suite (v) values (${"a"}), (${"b"}), (${"c"})`
|
|
126
|
+
expect(inserted.changes).toBe(3)
|
|
127
|
+
if (dialect === "postgres") expect(inserted.lastInsertId).toBeUndefined()
|
|
128
|
+
else expect(typeof inserted.lastInsertId).toBe("number")
|
|
129
|
+
expect((await db.sql<{ v: string }>`select v from hamur_suite order by v`).map((row) => row.v)).toEqual([
|
|
130
|
+
"a",
|
|
131
|
+
"b",
|
|
132
|
+
"c",
|
|
133
|
+
])
|
|
134
|
+
expect(await db.first<{ v: string }>`select v from hamur_suite order by v desc`).toEqual({ v: "c" })
|
|
135
|
+
expect(await db.first`select v from hamur_suite where v = ${"none"}`).toBeUndefined()
|
|
136
|
+
expect((await db.run`update hamur_suite set v = ${"z"} where v <> ${"a"}`).changes).toBe(2)
|
|
137
|
+
expect((await db.run`delete from hamur_suite where v = ${"none"}`).changes).toBe(0)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test("each value of the type table binds and reads back as the connector gives it", async () => {
|
|
141
|
+
await clear()
|
|
142
|
+
const at = new Date("2026-11-02T10:00:00.000Z")
|
|
143
|
+
const data = new Uint8Array([0, 1, 255])
|
|
144
|
+
await db.run`insert into hamur_suite (v, flag, at, data, big) values (${"row"}, ${true}, ${at}, ${data}, ${12n})`
|
|
145
|
+
await db.run`insert into hamur_suite (v, flag, at, data, big) values (${"nulls"}, ${false}, ${null}, ${null}, ${null})`
|
|
146
|
+
const row = (await db.first<
|
|
147
|
+
Record<string, unknown>
|
|
148
|
+
>`select flag, at, data, big from hamur_suite where v = ${"row"}`)!
|
|
149
|
+
expect(row.flag).toBe(dialect === "postgres" ? true : 1)
|
|
150
|
+
if (dialect === "sqlite") expect(row.at).toBe(at.toISOString())
|
|
151
|
+
else expect((row.at as Date).getTime()).toBe(at.getTime())
|
|
152
|
+
expect([...(row.data as Uint8Array)]).toEqual([0, 1, 255])
|
|
153
|
+
expect(row.big).toBe(dialect === "postgres" ? "12" : 12)
|
|
154
|
+
const nulls = (await db.first<
|
|
155
|
+
Record<string, unknown>
|
|
156
|
+
>`select flag, at, data, big from hamur_suite where v = ${"nulls"}`)!
|
|
157
|
+
expect(nulls).toEqual({ flag: dialect === "postgres" ? false : 0, at: null, data: null, big: null })
|
|
158
|
+
expect(await db.first`select v from hamur_suite where flag = ${true}`).toEqual({ v: "row" })
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test("an integer above 2^53 reads back as a number that lost precision on sqlite, a string elsewhere", async () => {
|
|
162
|
+
await clear()
|
|
163
|
+
await db.run`insert into hamur_suite (v, big) values (${"huge"}, ${9007199254740993n})`
|
|
164
|
+
const row = (await db.first<{ big: unknown }>`select big from hamur_suite where v = ${"huge"}`)!
|
|
165
|
+
expect(row.big).toBe(dialect === "sqlite" ? 9007199254740992 : "9007199254740993")
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test("exec runs text of several statements over several lines, with comments and blank lines", async () => {
|
|
169
|
+
await db.exec(`-- the suite's own table
|
|
170
|
+
create table hamur_exec (
|
|
171
|
+
id ${KEY[dialect]}, -- the key
|
|
172
|
+
v text not null
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
/* a second statement */
|
|
176
|
+
insert into hamur_exec (v) values ('a; -- not a comment');
|
|
177
|
+
`)
|
|
178
|
+
try {
|
|
179
|
+
expect(await db.sql`select v from hamur_exec`).toEqual([{ v: "a; -- not a comment" }])
|
|
180
|
+
} finally {
|
|
181
|
+
await db.exec("drop table hamur_exec")
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test("a value that cannot bind is refused before the query is sent, numbered from 1", async () => {
|
|
186
|
+
expect(() => db.sql`select ${1}, ${undefined as never}`).toThrow(
|
|
187
|
+
new TypeError("db.sql value 2 is undefined; pass null"),
|
|
188
|
+
)
|
|
189
|
+
expect(() => db.first`select ${Number.NaN}`).toThrow(new TypeError("db.first value 1 is NaN"))
|
|
190
|
+
expect(() => db.run`select ${1}, ${2}, ${{ a: 1 } as never}`).toThrow(
|
|
191
|
+
new TypeError("db.run value 3 is an object; bind JSON.stringify(value) for a json column"),
|
|
192
|
+
)
|
|
193
|
+
if (dialect === "postgres") {
|
|
194
|
+
await clear()
|
|
195
|
+
await db.run`insert into hamur_suite (v) values (${"a"}), (${"b"}), (${"c"})`
|
|
196
|
+
const ids = (await db.sql<{ id: number }>`select id from hamur_suite where v <> ${"b"}`).map((row) => row.id)
|
|
197
|
+
expect(
|
|
198
|
+
(await db.sql<{ v: string }>`select v from hamur_suite where id = any(${ids}) order by v`).map(
|
|
199
|
+
(row) => row.v,
|
|
200
|
+
),
|
|
201
|
+
).toEqual(["a", "c"])
|
|
202
|
+
} else {
|
|
203
|
+
const tail = dialect === "sqlite" ? "json_each" : "JSON_TABLE"
|
|
204
|
+
expect(() => db.sql`select ${[1, 2]}`).toThrow(
|
|
205
|
+
new TypeError(
|
|
206
|
+
`db.sql value 1 is an array, which ${dialect} cannot bind; bind one value per placeholder or JSON with ${tail}`,
|
|
207
|
+
),
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
if (transactions) {
|
|
213
|
+
test("transaction commits when fn resolves", async () => {
|
|
214
|
+
await clear()
|
|
215
|
+
const result = await db.transaction(async (tx) => {
|
|
216
|
+
await tx.run`insert into hamur_suite (v) values (${"t1"})`
|
|
217
|
+
await tx.run`insert into hamur_suite (v) values (${"t2"})`
|
|
218
|
+
return (await tx.sql`select v from hamur_suite`).length
|
|
219
|
+
})
|
|
220
|
+
expect(result).toBe(2)
|
|
221
|
+
expect(await values()).toEqual(["t1", "t2"])
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test("transaction rolls back when fn throws, and rethrows", async () => {
|
|
225
|
+
await clear()
|
|
226
|
+
const boom = new Error("boom")
|
|
227
|
+
const failed = db.transaction(async (tx) => {
|
|
228
|
+
await tx.run`insert into hamur_suite (v) values (${"gone"})`
|
|
229
|
+
throw boom
|
|
230
|
+
})
|
|
231
|
+
await expect(failed).rejects.toBe(boom)
|
|
232
|
+
expect(await values()).toEqual([])
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test("db inside its own transaction throws instead of deadlocking", async () => {
|
|
236
|
+
const seen: string[] = []
|
|
237
|
+
await db.transaction(async () => {
|
|
238
|
+
try {
|
|
239
|
+
db.sql`select 1`
|
|
240
|
+
} catch (error) {
|
|
241
|
+
seen.push((error as Error).message)
|
|
242
|
+
}
|
|
243
|
+
await db.transaction(async () => 1).catch((error: Error) => seen.push(error.message))
|
|
244
|
+
})
|
|
245
|
+
expect(seen).toEqual([
|
|
246
|
+
"db.sql was called inside db.transaction; use the tx argument",
|
|
247
|
+
"transaction cannot be nested; use the tx argument",
|
|
248
|
+
])
|
|
249
|
+
await other.transaction(async () => {
|
|
250
|
+
expect(await db.first<{ one: number }>`select 1 as one`).toEqual({ one: 1 })
|
|
251
|
+
})
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
test("a db query made before the transaction and awaited inside it fails and never runs", async () => {
|
|
255
|
+
await clear()
|
|
256
|
+
const early = db.run`insert into hamur_suite (v) values (${"early"})`
|
|
257
|
+
const seen = await Promise.race([
|
|
258
|
+
db.transaction(async () => {
|
|
259
|
+
try {
|
|
260
|
+
await early
|
|
261
|
+
return "ran"
|
|
262
|
+
} catch (error) {
|
|
263
|
+
return (error as Error).message
|
|
264
|
+
}
|
|
265
|
+
}),
|
|
266
|
+
sleep(2000).then(() => "deadlock"),
|
|
267
|
+
])
|
|
268
|
+
expect(seen).toBe("db.run was called inside db.transaction; use the tx argument")
|
|
269
|
+
expect(await values()).toEqual([])
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
if (dialect === "postgres") {
|
|
273
|
+
test("a failed statement that fn catches rolls the postgres transaction back, and the transaction rejects", async () => {
|
|
274
|
+
await clear()
|
|
275
|
+
const failed = db.transaction(async (tx) => {
|
|
276
|
+
await tx.run`insert into hamur_suite (v) values (${"lost"})`
|
|
277
|
+
await Promise.resolve(tx.run`insert into hamur_suite (v) values (${null})`).catch(() => {})
|
|
278
|
+
return "done"
|
|
279
|
+
})
|
|
280
|
+
await expect(failed).rejects.toThrow(
|
|
281
|
+
"transaction was rolled back: a statement in it failed, which aborts a postgres transaction; let the error end the transaction function, or run the statement in tx.batch",
|
|
282
|
+
)
|
|
283
|
+
expect(await values()).toEqual([])
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
test("a tx used after its transaction ended rejects", async () => {
|
|
288
|
+
let leaked!: Parameters<Parameters<Database["transaction"]>[0]>[0]
|
|
289
|
+
await db.transaction(async (tx) => {
|
|
290
|
+
leaked = tx
|
|
291
|
+
})
|
|
292
|
+
await expect(Promise.resolve(leaked.sql`select 1`)).rejects.toThrow(
|
|
293
|
+
"tx.sql was called after its transaction ended; run it inside the transaction function",
|
|
294
|
+
)
|
|
295
|
+
await expect(leaked.exec("select 1")).rejects.toThrow(
|
|
296
|
+
"tx.exec was called after its transaction ended; run it inside the transaction function",
|
|
297
|
+
)
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
test("a transaction that returns queries it did not await rolls back and rejects", async () => {
|
|
301
|
+
await clear()
|
|
302
|
+
await expect(
|
|
303
|
+
db.transaction(async (tx) => [tx.run`insert into hamur_suite (v) values (${"late"})`]),
|
|
304
|
+
).rejects.toThrow("transaction returned a query it did not await; await it inside the transaction function")
|
|
305
|
+
expect(await values()).toEqual([])
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
test("tx.batch is all or nothing even when its error is caught inside the transaction", async () => {
|
|
309
|
+
await clear()
|
|
310
|
+
await db.transaction(async (tx) => {
|
|
311
|
+
await tx.run`insert into hamur_suite (v) values (${"kept"})`
|
|
312
|
+
await expect(
|
|
313
|
+
tx.batch([
|
|
314
|
+
tx.run`insert into hamur_suite (v) values (${"b1"})`,
|
|
315
|
+
tx.run`insert into hamur_suite (v) values (${null})`,
|
|
316
|
+
]),
|
|
317
|
+
).rejects.toThrow()
|
|
318
|
+
const [rows] = await tx.batch([tx.sql<{ v: string }>`select v from hamur_suite order by id`])
|
|
319
|
+
expect(rows.map((row) => row.v)).toEqual(["kept"])
|
|
320
|
+
})
|
|
321
|
+
expect(await values()).toEqual(["kept"])
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
test("close inside the transaction rejects instead of waiting for itself", async () => {
|
|
325
|
+
const seen = await db.transaction(async () =>
|
|
326
|
+
db.close().then(
|
|
327
|
+
() => "closed",
|
|
328
|
+
(error: Error) => error.message,
|
|
329
|
+
),
|
|
330
|
+
)
|
|
331
|
+
expect(seen).toBe("db.close was called inside db.transaction; close it after the transaction ends")
|
|
332
|
+
expect(await db.first<{ one: number }>`select 1 as one`).toEqual({ one: 1 })
|
|
333
|
+
})
|
|
334
|
+
} else {
|
|
335
|
+
test("transaction is refused: the connector has no interactive transactions", async () => {
|
|
336
|
+
await expect(db.transaction(async () => 1)).rejects.toThrow(TRANSACTION_REFUSED)
|
|
337
|
+
expect(await db.first<{ one: number }>`select 1 as one`).toEqual({ one: 1 })
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
test("batch runs the queries in order as one unit and resolves to their results", async () => {
|
|
342
|
+
await clear()
|
|
343
|
+
const [inserted, rows, row] = await db.batch([
|
|
344
|
+
db.run`insert into hamur_suite (v) values (${"b1"})`,
|
|
345
|
+
db.sql<{ v: string }>`select v from hamur_suite`,
|
|
346
|
+
db.first<{ v: string }>`select v from hamur_suite`,
|
|
347
|
+
])
|
|
348
|
+
expect(inserted.changes).toBe(1)
|
|
349
|
+
expect(rows).toEqual([{ v: "b1" }])
|
|
350
|
+
expect(row).toEqual({ v: "b1" })
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
test("a failed query rolls the whole batch back and rejects with its error", async () => {
|
|
354
|
+
await clear()
|
|
355
|
+
await expect(
|
|
356
|
+
db.batch([
|
|
357
|
+
db.run`insert into hamur_suite (v) values (${"b1"})`,
|
|
358
|
+
db.run`insert into hamur_suite (v) values (${null})`,
|
|
359
|
+
]),
|
|
360
|
+
).rejects.toThrow()
|
|
361
|
+
expect(await values()).toEqual([])
|
|
362
|
+
await expect(db.batch([other.sql`select 1`])).rejects.toThrow(
|
|
363
|
+
'batch takes queries of this database ("default"), got one of "analytics"',
|
|
364
|
+
)
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
if (dialect === "sqlite" && transactions) {
|
|
368
|
+
test("other statements of the process wait until the transaction ends", async () => {
|
|
369
|
+
await clear()
|
|
370
|
+
let release!: () => void
|
|
371
|
+
const gate = new Promise<void>((resolve) => (release = resolve))
|
|
372
|
+
const running = db.transaction(async (tx) => {
|
|
373
|
+
await tx.run`insert into hamur_suite (v) values (${"inside"})`
|
|
374
|
+
await gate
|
|
375
|
+
throw new Error("undo")
|
|
376
|
+
})
|
|
377
|
+
await sleep(5)
|
|
378
|
+
let done = false
|
|
379
|
+
const outside = db.run`insert into hamur_suite (v) values (${"outside"})`.then(() => void (done = true))
|
|
380
|
+
await sleep(5)
|
|
381
|
+
expect(done).toBe(false)
|
|
382
|
+
release()
|
|
383
|
+
await expect(running).rejects.toThrow("undo")
|
|
384
|
+
await outside
|
|
385
|
+
expect(await values()).toEqual(["outside"])
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
test("close ends the connection; a query after it rejects", async () => {
|
|
390
|
+
const own = createDatabase("closing", dialect, open)
|
|
391
|
+
expect(await own.first<{ one: number }>`select 1 as one`).toEqual({ one: 1 })
|
|
392
|
+
await own.close()
|
|
393
|
+
await expect(Promise.resolve(own.sql`select 1`)).rejects.toThrow('Database "closing" is closed')
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
test("a query that starts while close runs rejects and opens no connection", async () => {
|
|
397
|
+
let opened = 0
|
|
398
|
+
const own = createDatabase("racing", dialect, () => (opened++, open()))
|
|
399
|
+
const closing = own.close()
|
|
400
|
+
const late = Promise.resolve(own.sql`select 1`)
|
|
401
|
+
await closing
|
|
402
|
+
await expect(late).rejects.toThrow('Database "racing" is closed')
|
|
403
|
+
expect(opened).toBe(0)
|
|
404
|
+
})
|
|
405
|
+
})
|
|
406
|
+
}
|
package/src/devtools.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { defineDevtoolsApp } from "hamur/app"
|
|
2
|
+
import type { MigrationState } from "./runtime/migrate.ts"
|
|
3
|
+
|
|
4
|
+
interface Tables {
|
|
5
|
+
connection: string
|
|
6
|
+
connections: string[]
|
|
7
|
+
dialect: string
|
|
8
|
+
tables: string[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Rows {
|
|
12
|
+
table: string
|
|
13
|
+
page: number
|
|
14
|
+
pageSize: number
|
|
15
|
+
total: number
|
|
16
|
+
columns: string[]
|
|
17
|
+
rows: Array<Record<string, unknown>>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface QueryResult {
|
|
21
|
+
columns: string[]
|
|
22
|
+
rows: Array<Record<string, unknown>>
|
|
23
|
+
truncated: boolean
|
|
24
|
+
ms: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const FOCUS = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
|
|
28
|
+
const BUTTON = `inline-flex items-center gap-1.5 h-6 px-2 rounded-md border-0 bg-transparent text-fg-2 ring-1 ring-inset ring-line-strong font-medium text-sm whitespace-nowrap cursor-pointer hover:bg-hover hover:text-fg disabled:opacity-40 disabled:cursor-default ${FOCUS}`
|
|
29
|
+
const PRIMARY = `inline-flex items-center gap-1.5 h-6 px-2 rounded-md border-0 bg-fg text-app font-medium text-sm whitespace-nowrap cursor-pointer disabled:opacity-40 disabled:cursor-default ${FOCUS}`
|
|
30
|
+
const FIELD = `h-6 min-w-0 px-2 rounded-md border-0 bg-field ring-1 ring-inset ring-line text-xs text-fg ${FOCUS}`
|
|
31
|
+
const TABLE_BUTTON = `flex items-center w-full min-h-7 px-2.5 py-1 border-0 rounded-md bg-transparent text-left font-mono text-sm font-medium text-fg break-all cursor-pointer hover:bg-hover ${FOCUS}`
|
|
32
|
+
const HEAD = "flex items-center gap-2 h-8 mt-1 px-4 bg-field text-xs font-medium text-fg-2"
|
|
33
|
+
const HINT = "m-0 px-4 py-2 text-xs text-fg-3"
|
|
34
|
+
const FAIL = "m-0 px-4 py-2 text-xs text-red whitespace-pre-wrap"
|
|
35
|
+
const CHIP_COLORS: Record<string, string> = { applied: "text-green", changed: "text-red", "missing file": "text-red" }
|
|
36
|
+
|
|
37
|
+
const element = <K extends keyof HTMLElementTagNameMap>(
|
|
38
|
+
tag: K,
|
|
39
|
+
props: Partial<HTMLElementTagNameMap[K]> = {},
|
|
40
|
+
...children: (Node | string)[]
|
|
41
|
+
): HTMLElementTagNameMap[K] => {
|
|
42
|
+
const node = Object.assign(document.createElement(tag), props)
|
|
43
|
+
node.append(...children)
|
|
44
|
+
return node
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const messageOf = (error: unknown): string => (error instanceof Error ? error.message : String(error))
|
|
48
|
+
|
|
49
|
+
async function call<T>(path: string, init?: RequestInit): Promise<T> {
|
|
50
|
+
const response = await fetch(`api/db/${path}`, init)
|
|
51
|
+
const body = (await response.json().catch(() => ({}))) as { error?: string }
|
|
52
|
+
if (!response.ok) throw new Error(body.error ?? `api/db/${path} answered ${response.status}`)
|
|
53
|
+
return body as T
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A cell as the grid shows it: `NULL` for null, JSON for an object. */
|
|
57
|
+
export function cellText(value: unknown): string {
|
|
58
|
+
if (value === null || value === undefined) return "NULL"
|
|
59
|
+
return typeof value === "object" ? JSON.stringify(value) : String(value)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The pages a table of `total` rows has, at least one. */
|
|
63
|
+
export const pageCount = (total: number, pageSize: number): number => Math.max(1, Math.ceil(total / pageSize))
|
|
64
|
+
|
|
65
|
+
function grid(columns: string[], rows: Array<Record<string, unknown>>): HTMLElement {
|
|
66
|
+
if (!columns.length) return element("p", { className: HINT }, "No rows")
|
|
67
|
+
const table = element(
|
|
68
|
+
"table",
|
|
69
|
+
{ className: "w-full border-collapse font-mono text-xs" },
|
|
70
|
+
element(
|
|
71
|
+
"thead",
|
|
72
|
+
{ className: "sticky top-0 bg-panel" },
|
|
73
|
+
element(
|
|
74
|
+
"tr",
|
|
75
|
+
{},
|
|
76
|
+
...columns.map((column) =>
|
|
77
|
+
element(
|
|
78
|
+
"th",
|
|
79
|
+
{ className: "h-8 px-2.5 border-b border-line text-left font-medium text-fg-3 whitespace-nowrap" },
|
|
80
|
+
column,
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
),
|
|
85
|
+
element(
|
|
86
|
+
"tbody",
|
|
87
|
+
{},
|
|
88
|
+
...rows.map((row) =>
|
|
89
|
+
element(
|
|
90
|
+
"tr",
|
|
91
|
+
{ className: "hover:bg-hover" },
|
|
92
|
+
...columns.map((column) =>
|
|
93
|
+
element("td", { className: "h-7 px-2.5 text-fg-2 whitespace-nowrap" }, cellText(row[column])),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
return element("div", { className: "overflow-auto max-h-96" }, table)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default defineDevtoolsApp({
|
|
103
|
+
init(canvas) {
|
|
104
|
+
canvas.className = "flex flex-1 min-h-0"
|
|
105
|
+
const heading = (title: string) => element("h2", { className: `m-0 ${HEAD}` }, title)
|
|
106
|
+
const select = element("select", { name: "connection", className: `${FIELD} mx-1.5 mb-1.5` })
|
|
107
|
+
select.setAttribute("aria-label", "Connection")
|
|
108
|
+
const tableList = element("ul", { className: "m-0 px-1.5 list-none" })
|
|
109
|
+
const rowsBox = element("section", {}, heading("Rows"), element("p", { className: HINT }, "Choose a table"))
|
|
110
|
+
const sql = element("textarea", {
|
|
111
|
+
name: "sql",
|
|
112
|
+
rows: 4,
|
|
113
|
+
spellcheck: false,
|
|
114
|
+
placeholder: "select * from …",
|
|
115
|
+
className: `block w-full px-3.5 py-3 rounded-lg border-0 bg-field ring-1 ring-inset ring-line font-mono text-sm text-fg placeholder:text-fg-4 ${FOCUS}`,
|
|
116
|
+
})
|
|
117
|
+
sql.setAttribute("aria-label", "SQL statement")
|
|
118
|
+
const run = element("button", { type: "submit", className: PRIMARY }, "Run")
|
|
119
|
+
const result = element("div")
|
|
120
|
+
const form = element(
|
|
121
|
+
"form",
|
|
122
|
+
{ className: "flex flex-col gap-2 px-4 py-3" },
|
|
123
|
+
sql,
|
|
124
|
+
element("div", { className: "flex items-center gap-2.5" }, run),
|
|
125
|
+
result,
|
|
126
|
+
)
|
|
127
|
+
const migrationsBox = element("section", {}, heading("Migrations"))
|
|
128
|
+
canvas.append(
|
|
129
|
+
element(
|
|
130
|
+
"aside",
|
|
131
|
+
{ className: "w-60 flex-none flex flex-col py-1.5 border-r border-line overflow-auto" },
|
|
132
|
+
heading("Tables"),
|
|
133
|
+
select,
|
|
134
|
+
tableList,
|
|
135
|
+
migrationsBox,
|
|
136
|
+
),
|
|
137
|
+
element("div", { className: "flex-1 min-w-0 flex flex-col overflow-auto" }, rowsBox, heading("SQL"), form),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
let connection = "default"
|
|
141
|
+
let table: string | undefined
|
|
142
|
+
|
|
143
|
+
async function showRows(name: string, page: number): Promise<void> {
|
|
144
|
+
table = name
|
|
145
|
+
for (const button of tableList.querySelectorAll<HTMLButtonElement>("button[data-table]")) {
|
|
146
|
+
if (button.dataset.table === name) button.setAttribute("aria-current", "true")
|
|
147
|
+
else button.removeAttribute("aria-current")
|
|
148
|
+
button.classList.toggle("bg-active", button.dataset.table === name)
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const answer = await call<Rows>(`rows?${new URLSearchParams({ connection, table: name, page: String(page) })}`)
|
|
152
|
+
const pages = pageCount(answer.total, answer.pageSize)
|
|
153
|
+
const previous = element("button", { type: "button", disabled: page <= 1, className: BUTTON }, "Previous")
|
|
154
|
+
const next = element("button", { type: "button", disabled: page >= pages, className: BUTTON }, "Next")
|
|
155
|
+
previous.addEventListener("click", () => void showRows(name, page - 1))
|
|
156
|
+
next.addEventListener("click", () => void showRows(name, page + 1))
|
|
157
|
+
const pager = element(
|
|
158
|
+
"div",
|
|
159
|
+
{ className: "flex items-center gap-2 px-4 py-2" },
|
|
160
|
+
previous,
|
|
161
|
+
element("span", { className: "text-xs text-fg-3" }, `Page ${page} of ${pages} · ${answer.total} rows`),
|
|
162
|
+
next,
|
|
163
|
+
)
|
|
164
|
+
rowsBox.replaceChildren(heading(name), grid(answer.columns, answer.rows), pager)
|
|
165
|
+
rowsBox.dataset.table = name
|
|
166
|
+
rowsBox.dataset.page = String(page)
|
|
167
|
+
} catch (error) {
|
|
168
|
+
rowsBox.replaceChildren(heading(name), element("p", { className: FAIL }, messageOf(error)))
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async function showMigrations(): Promise<void> {
|
|
173
|
+
try {
|
|
174
|
+
const states = await call<MigrationState[]>(`migrations?${new URLSearchParams({ connection })}`)
|
|
175
|
+
const list = element(
|
|
176
|
+
"ul",
|
|
177
|
+
{ className: "m-0 px-1.5 list-none" },
|
|
178
|
+
...states.map((state) => {
|
|
179
|
+
const chip = element(
|
|
180
|
+
"span",
|
|
181
|
+
{ className: `flex-none w-20 text-2xs font-medium ${CHIP_COLORS[state.state] ?? "text-fg-3"}` },
|
|
182
|
+
state.state,
|
|
183
|
+
)
|
|
184
|
+
chip.dataset.state = state.state
|
|
185
|
+
const item = element(
|
|
186
|
+
"li",
|
|
187
|
+
{ className: "flex items-center gap-2 min-h-7 px-2.5" },
|
|
188
|
+
chip,
|
|
189
|
+
element("code", { className: "min-w-0 truncate font-mono text-xs text-fg" }, `${state.id}_${state.name}`),
|
|
190
|
+
...(state.state === "applied"
|
|
191
|
+
? [element("span", { className: "text-2xs text-fg-4" }, state.appliedAt)]
|
|
192
|
+
: []),
|
|
193
|
+
)
|
|
194
|
+
item.dataset.migration = state.id
|
|
195
|
+
return item
|
|
196
|
+
}),
|
|
197
|
+
)
|
|
198
|
+
migrationsBox.replaceChildren(
|
|
199
|
+
heading("Migrations"),
|
|
200
|
+
states.length ? list : element("p", { className: HINT }, "No migrations"),
|
|
201
|
+
)
|
|
202
|
+
} catch (error) {
|
|
203
|
+
migrationsBox.replaceChildren(heading("Migrations"), element("p", { className: FAIL }, messageOf(error)))
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function showConnection(): Promise<void> {
|
|
208
|
+
table = undefined
|
|
209
|
+
rowsBox.replaceChildren(heading("Rows"), element("p", { className: HINT }, "Choose a table"))
|
|
210
|
+
try {
|
|
211
|
+
const answer = await call<Tables>(`tables?${new URLSearchParams({ connection })}`)
|
|
212
|
+
select.replaceChildren(
|
|
213
|
+
...answer.connections.map((name) =>
|
|
214
|
+
element("option", { value: name, selected: name === answer.connection }, name),
|
|
215
|
+
),
|
|
216
|
+
)
|
|
217
|
+
tableList.replaceChildren(
|
|
218
|
+
...answer.tables.map((name) => {
|
|
219
|
+
const button = element("button", { type: "button", className: TABLE_BUTTON }, name)
|
|
220
|
+
button.dataset.table = name
|
|
221
|
+
button.addEventListener("click", () => void showRows(name, 1))
|
|
222
|
+
return element("li", {}, button)
|
|
223
|
+
}),
|
|
224
|
+
)
|
|
225
|
+
if (!answer.tables.length) tableList.replaceChildren(element("li", { className: HINT }, "No tables"))
|
|
226
|
+
} catch (error) {
|
|
227
|
+
tableList.replaceChildren(element("li", { className: FAIL }, messageOf(error)))
|
|
228
|
+
}
|
|
229
|
+
await showMigrations()
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
select.addEventListener("change", () => {
|
|
233
|
+
connection = select.value
|
|
234
|
+
void showConnection()
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
form.addEventListener("submit", async (event) => {
|
|
238
|
+
event.preventDefault()
|
|
239
|
+
run.disabled = true
|
|
240
|
+
try {
|
|
241
|
+
const answer = await call<QueryResult>("query", {
|
|
242
|
+
method: "POST",
|
|
243
|
+
headers: { "content-type": "application/json" },
|
|
244
|
+
body: JSON.stringify({ connection, sql: sql.value }),
|
|
245
|
+
})
|
|
246
|
+
const note = `${answer.rows.length}${answer.truncated ? "+" : ""} rows in ${answer.ms} ms${answer.truncated ? `, the first ${answer.rows.length} shown` : ""}`
|
|
247
|
+
const status = element("p", { className: "m-0 text-xs text-fg-3" }, note)
|
|
248
|
+
status.dataset.rows = String(answer.rows.length)
|
|
249
|
+
result.replaceChildren(status, grid(answer.columns, answer.rows))
|
|
250
|
+
const [shown, page] = [table, Number(rowsBox.dataset.page ?? "1")]
|
|
251
|
+
await showConnection()
|
|
252
|
+
if (shown !== undefined) await showRows(shown, page)
|
|
253
|
+
} catch (error) {
|
|
254
|
+
result.replaceChildren(
|
|
255
|
+
element("p", { className: "m-0 text-xs text-red whitespace-pre-wrap" }, messageOf(error)),
|
|
256
|
+
)
|
|
257
|
+
} finally {
|
|
258
|
+
run.disabled = false
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
void showConnection()
|
|
263
|
+
},
|
|
264
|
+
})
|