-
Notifications
You must be signed in to change notification settings - Fork 198
/
database.spec.ts
46 lines (41 loc) 路 1.17 KB
/
database.spec.ts
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
import { BetaDatabase } from "@miniflare/d1";
import { Storage } from "@miniflare/shared";
import { testClock } from "@miniflare/shared-test";
import { MemoryStorage } from "@miniflare/storage-memory";
import anyTest, { TestInterface } from "ava";
interface Context {
storage: Storage;
db: BetaDatabase;
}
const test = anyTest as TestInterface<Context>;
test.beforeEach(async (t) => {
const storage = new MemoryStorage(undefined, testClock);
const db = new BetaDatabase(await storage.getSqliteDatabase());
t.context = { storage, db };
});
test("batch, prepare & all", async (t) => {
const { db } = t.context;
await db.batch([
db.prepare(
`CREATE TABLE my_table (cid INTEGER PRIMARY KEY, name TEXT NOT NULL);`
),
]);
const response = await db.prepare(`SELECT * FROM sqlite_schema`).all();
t.deepEqual(Object.keys(response), [
"results",
"duration",
"lastRowId",
"changes",
"success",
"served_by",
]);
t.deepEqual(response.results, [
{
type: "table",
name: "my_table",
tbl_name: "my_table",
rootpage: 2,
sql: "CREATE TABLE my_table (cid INTEGER PRIMARY KEY, name TEXT NOT NULL)",
},
]);
});