-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknex.test.ts
44 lines (39 loc) · 1.01 KB
/
knex.test.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
import { config, getUsers, User } from "./knex";
import _ from "lodash";
import knex from "knex";
describe("test knex use mysql", () => {
const mysqlKnex = knex(config.mysql);
afterAll(async () => {
await mysqlKnex.destroy();
});
test("test getUsers", async () => {
const users = await getUsers();
expect(users).toEqual([]);
});
test("test view built sql", () => {
const sql = mysqlKnex<User>("users")
.select("id")
.where("age", ">", 20)
.toSQL()
.toNative();
expect(sql).toEqual("");
});
test("test update multiple columns", async () => {
await mysqlKnex<User>("users")
.update({
name: "zyd new",
age: 40,
})
.where("id", 1);
});
});
describe("test knex with sqlite3", () => {
const sqlite3Knex = knex(config.sqlite3);
afterAll(async () => {
await sqlite3Knex.destroy();
});
test("test migration", async () => {
await sqlite3Knex.migrate.latest();
await sqlite3Knex.migrate.rollback({}, true);
});
});