-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathquery.ts
More file actions
42 lines (36 loc) · 1016 Bytes
/
query.ts
File metadata and controls
42 lines (36 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { createClient } from "@libsql/client";
import { prettyPrintDuration } from "./utils.ts"
if (process.env.DB_URL === undefined) {
throw new Error("DB_URL must be set");
}
if (process.env.AUTH_TOKEN === undefined) {
throw new Error("AUTH_TOKEN must be set");
}
const client = createClient({
url: process.env.DB_URL,
authToken: process.env.AUTH_TOKEN,
syncUrl: process.env.SYNC_URL,
});
if (process.env.SYNC_URL != undefined) {
await client.sync();
}
const queries = 25;
const start = Bun.nanoseconds();
for (let i = 0; i < queries; i++) {
const rs = await client.execute(
"SELECT u.name, k.expired FROM users u JOIN keycards as k ON u.user_id = k.user_id",
);
for (const row of rs.rows) {
console.log(
`The keycard for user ${row.name} is ${
row.expired ? "expired" : "valid"
}`,
);
}
}
const delta = (Bun.nanoseconds() - start) / 1000;
console.log(
`took ${prettyPrintDuration(delta)}, ${prettyPrintDuration(
delta / queries,
)} per query`,
);