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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import { expect, it } from "bun:test";
var SQL = globalThis[Symbol.for("Bun.lazy")]("sqlite");
it("works", () => {
const handle = SQL.open("/tmp/northwind.sqlite");
const stmt = SQL.prepare(
handle,
'SELECT * FROM "Order" WHERE OrderDate > date($date)'
);
expect(stmt.toString()).toBe(
`SELECT * FROM "Order" WHERE OrderDate > date(NULL)`
);
expect(
Array.isArray(
stmt.all({
// do the conversion this way so that this test runs in multiple timezones
$date: new Date(
new Date(1996, 8, 1, 0, 0, 0, 0).toUTCString()
).toISOString(),
})
)
).toBe(true);
expect(stmt.toString()).toBe(
`SELECT * FROM "Order" WHERE OrderDate > date('1996-09-01T07:00:00.000Z')`
);
var ran = stmt.run({
$date: new Date(
new Date(1997, 8, 1, 0, 0, 0, 0).toUTCString()
).toISOString(),
});
expect(Array.isArray(ran)).toBe(false);
expect(ran === undefined).toBe(true);
expect(stmt.toString()).toBe(
`SELECT * FROM "Order" WHERE OrderDate > date('1997-09-01T07:00:00.000Z')`
);
expect(
Array.isArray(
stmt.get({
$date: new Date(
new Date(1998, 8, 1, 0, 0, 0, 0).toUTCString()
).toISOString(),
})
)
).toBe(false);
expect(stmt.toString()).toBe(
`SELECT * FROM "Order" WHERE OrderDate > date('1998-09-01T07:00:00.000Z')`
);
expect(stmt.paramsCount).toBe(1);
expect(stmt.columnsCount).toBe(14);
expect(stmt.columns.length).toBe(14);
stmt.finalize();
SQL.close(handle);
});
it("SQL.run works", () => {
const handle = SQL.open("/tmp/northwind.sqlite");
expect(typeof handle).toBe("number");
expect(
SQL.run(handle, 'SELECT * FROM "Order" WHERE OrderDate > date($date)', {
$date: new Date(1996, 8, 1).toISOString(),
})
).toBe(undefined);
SQL.close(handle);
});
|