@saltcorn/data 0.6.3 → 0.6.4-beta.1
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/dist/base-plugin/index.d.ts +118 -101
- package/dist/base-plugin/index.d.ts.map +1 -1
- package/dist/base-plugin/types.d.ts +105 -85
- package/dist/base-plugin/types.d.ts.map +1 -1
- package/dist/base-plugin/types.js +29 -1
- package/dist/base-plugin/types.js.map +1 -1
- package/dist/base-plugin/viewtemplates/list.d.ts +1 -1
- package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/list.js +8 -1
- package/dist/base-plugin/viewtemplates/list.js.map +1 -1
- package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/show.js +2 -3
- package/dist/base-plugin/viewtemplates/show.js.map +1 -1
- package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/viewable_fields.js +9 -11
- package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
- package/dist/db/connect.d.ts.map +1 -1
- package/dist/db/connect.js +7 -1
- package/dist/db/connect.js.map +1 -1
- package/dist/models/backup.d.ts +1 -1
- package/dist/models/backup.js.map +1 -1
- package/dist/models/crash.d.ts +1 -1
- package/dist/models/crash.d.ts.map +1 -1
- package/dist/models/crash.js.map +1 -1
- package/dist/models/discovery.d.ts +17 -25
- package/dist/models/discovery.d.ts.map +1 -1
- package/dist/models/discovery.js +38 -26
- package/dist/models/discovery.js.map +1 -1
- package/dist/models/eventlog.d.ts +1 -1
- package/dist/models/eventlog.d.ts.map +1 -1
- package/dist/models/eventlog.js.map +1 -1
- package/dist/models/expression.d.ts +11 -9
- package/dist/models/expression.d.ts.map +1 -1
- package/dist/models/expression.js +15 -13
- package/dist/models/expression.js.map +1 -1
- package/dist/models/field.d.ts +10 -45
- package/dist/models/field.d.ts.map +1 -1
- package/dist/models/field.js +3 -3
- package/dist/models/field.js.map +1 -1
- package/dist/models/file.d.ts +1 -1
- package/dist/models/file.d.ts.map +1 -1
- package/dist/models/file.js.map +1 -1
- package/dist/models/library.d.ts +1 -1
- package/dist/models/library.d.ts.map +1 -1
- package/dist/models/pack.d.ts +10 -7
- package/dist/models/pack.d.ts.map +1 -1
- package/dist/models/pack.js +0 -4
- package/dist/models/pack.js.map +1 -1
- package/dist/models/page.d.ts +4 -5
- package/dist/models/page.d.ts.map +1 -1
- package/dist/models/plugin.d.ts +4 -4
- package/dist/models/plugin.d.ts.map +1 -1
- package/dist/models/plugin.js.map +1 -1
- package/dist/models/random.d.ts +18 -21
- package/dist/models/random.d.ts.map +1 -1
- package/dist/models/random.js +31 -29
- package/dist/models/random.js.map +1 -1
- package/dist/models/scheduler.d.ts +1 -1
- package/dist/models/scheduler.d.ts.map +1 -1
- package/dist/models/table.d.ts +8 -8
- package/dist/models/table.d.ts.map +1 -1
- package/dist/models/table.js +13 -5
- package/dist/models/table.js.map +1 -1
- package/dist/models/table_constraints.d.ts +1 -1
- package/dist/models/table_constraints.d.ts.map +1 -1
- package/dist/models/table_constraints.js +4 -1
- package/dist/models/table_constraints.js.map +1 -1
- package/dist/models/tenant.d.ts +16 -60
- package/dist/models/tenant.d.ts.map +1 -1
- package/dist/models/tenant.js +52 -30
- package/dist/models/tenant.js.map +1 -1
- package/dist/models/trigger.d.ts +1 -1
- package/dist/models/trigger.d.ts.map +1 -1
- package/dist/models/trigger.js +1 -1
- package/dist/models/trigger.js.map +1 -1
- package/dist/models/user.d.ts +3 -1
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js.map +1 -1
- package/dist/models/view.d.ts +3 -2
- package/dist/models/view.d.ts.map +1 -1
- package/dist/models/view.js +1 -1
- package/dist/models/view.js.map +1 -1
- package/dist/models/workflow.d.ts +4 -4
- package/dist/models/workflow.d.ts.map +1 -1
- package/dist/models/workflow.js.map +1 -1
- package/dist/plugin-helper.d.ts.map +1 -1
- package/dist/plugin-helper.js +2 -2
- package/dist/plugin-helper.js.map +1 -1
- package/dist/tests/actions.test.d.ts.map +1 -1
- package/dist/tests/actions.test.js +102 -82
- package/dist/tests/actions.test.js.map +1 -1
- package/dist/tests/assertions.d.ts +13 -0
- package/dist/tests/assertions.d.ts.map +1 -0
- package/dist/tests/assertions.js +35 -0
- package/dist/tests/assertions.js.map +1 -0
- package/dist/tests/auxtest.test.d.ts.map +1 -1
- package/dist/tests/auxtest.test.js +33 -29
- package/dist/tests/auxtest.test.js.map +1 -1
- package/dist/tests/backup.test.d.ts.map +1 -1
- package/dist/tests/backup.test.js +62 -49
- package/dist/tests/backup.test.js.map +1 -1
- package/dist/tests/calc.test.d.ts.map +1 -1
- package/dist/tests/calc.test.js +106 -88
- package/dist/tests/calc.test.js.map +1 -1
- package/dist/tests/config.test.d.ts.map +1 -1
- package/dist/tests/config.test.js +39 -36
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/discover.test.d.ts.map +1 -1
- package/dist/tests/discover.test.js +23 -17
- package/dist/tests/discover.test.js.map +1 -1
- package/dist/tests/exact_views.test.d.ts.map +1 -1
- package/dist/tests/exact_views.test.js +65 -24
- package/dist/tests/exact_views.test.js.map +1 -1
- package/dist/tests/field.test.d.ts.map +1 -1
- package/dist/tests/field.test.js +104 -93
- package/dist/tests/field.test.js.map +1 -1
- package/dist/tests/form.test.d.ts.map +1 -1
- package/dist/tests/form.test.js +71 -63
- package/dist/tests/form.test.js.map +1 -1
- package/dist/tests/mocks.d.ts +101 -105
- package/dist/tests/mocks.d.ts.map +1 -1
- package/dist/tests/mocks.js +19 -14
- package/dist/tests/mocks.js.map +1 -1
- package/dist/tests/models.test.d.ts.map +1 -1
- package/dist/tests/models.test.js +95 -80
- package/dist/tests/models.test.js.map +1 -1
- package/dist/tests/pack.test.d.ts.map +1 -1
- package/dist/tests/pack.test.js +54 -47
- package/dist/tests/pack.test.js.map +1 -1
- package/dist/tests/plugin.test.d.ts.map +1 -1
- package/dist/tests/plugin.test.js +31 -24
- package/dist/tests/plugin.test.js.map +1 -1
- package/dist/tests/random.test.d.ts.map +1 -1
- package/dist/tests/random.test.js +61 -50
- package/dist/tests/random.test.js.map +1 -1
- package/dist/tests/table.test.d.ts.map +1 -1
- package/dist/tests/table.test.js +539 -449
- package/dist/tests/table.test.js.map +1 -1
- package/dist/tests/tenant.test.d.ts.map +1 -1
- package/dist/tests/tenant.test.js +30 -23
- package/dist/tests/tenant.test.js.map +1 -1
- package/dist/tests/user.test.d.ts.map +1 -1
- package/dist/tests/user.test.js +128 -100
- package/dist/tests/user.test.js.map +1 -1
- package/dist/tests/view.test.d.ts.map +1 -1
- package/dist/tests/view.test.js +109 -85
- package/dist/tests/view.test.js.map +1 -1
- package/dist/tests/workflow.test.d.ts.map +1 -1
- package/dist/tests/workflow.test.js +40 -29
- package/dist/tests/workflow.test.js.map +1 -1
- package/dist/tsconfig.ref.tsbuildinfo +1 -1
- package/package.json +15 -8
package/dist/tests/table.test.js
CHANGED
|
@@ -1,49 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const table_1 = __importDefault(require("../models/table"));
|
|
7
|
+
const table_constraints_1 = __importDefault(require("../models/table_constraints"));
|
|
8
|
+
const field_1 = __importDefault(require("../models/field"));
|
|
9
|
+
const view_1 = __importDefault(require("../models/view"));
|
|
10
|
+
const db_1 = __importDefault(require("../db"));
|
|
7
11
|
const { getState } = require("../db/state");
|
|
8
12
|
getState().registerPlugin("base", require("../base-plugin"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const promises_1 = require("fs/promises");
|
|
14
|
+
const mocks_1 = __importDefault(require("./mocks"));
|
|
15
|
+
const { rick_file, plugin_with_routes, mockReqRes } = mocks_1.default;
|
|
16
|
+
const assertions_1 = require("./assertions");
|
|
17
|
+
const globals_1 = require("@jest/globals");
|
|
18
|
+
(0, globals_1.afterAll)(db_1.default.close);
|
|
19
|
+
(0, globals_1.beforeAll)(async () => {
|
|
13
20
|
await require("../db/reset_schema")();
|
|
14
21
|
await require("../db/fixtures")();
|
|
15
22
|
});
|
|
16
23
|
jest.setTimeout(30000);
|
|
17
|
-
describe("TableIO", () => {
|
|
18
|
-
it("should store attributes", async () => {
|
|
19
|
-
const tc = await
|
|
20
|
-
await
|
|
24
|
+
(0, globals_1.describe)("TableIO", () => {
|
|
25
|
+
(0, globals_1.it)("should store attributes", async () => {
|
|
26
|
+
const tc = await table_1.default.create("mytesttable");
|
|
27
|
+
await field_1.default.create({
|
|
21
28
|
table: tc,
|
|
22
29
|
name: "foo_height1",
|
|
23
30
|
label: "height1",
|
|
24
31
|
type: "Integer",
|
|
25
32
|
attributes: { max: 18 },
|
|
26
33
|
});
|
|
27
|
-
const fs = await
|
|
28
|
-
expect(fs.table_id).toBe(tc.id);
|
|
29
|
-
expect(fs.table_id > 0).toBe(true);
|
|
30
|
-
expect(fs.id > 0).toBe(true);
|
|
34
|
+
const fs = await db_1.default.selectOne("_sc_fields", { name: "foo_height1" });
|
|
35
|
+
(0, globals_1.expect)(fs.table_id).toBe(tc.id);
|
|
36
|
+
(0, globals_1.expect)(fs.table_id > 0).toBe(true);
|
|
37
|
+
(0, globals_1.expect)(fs.id > 0).toBe(true);
|
|
31
38
|
const fields = await tc.getFields();
|
|
32
|
-
expect(fields[1].attributes).toStrictEqual({ max: 18 });
|
|
39
|
+
(0, globals_1.expect)(fields[1].attributes).toStrictEqual({ max: 18 });
|
|
33
40
|
});
|
|
34
41
|
});
|
|
35
|
-
describe("Table create", () => {
|
|
36
|
-
it("should create", async () => {
|
|
37
|
-
const tc = await
|
|
38
|
-
const tf = await
|
|
39
|
-
|
|
40
|
-
expect(
|
|
41
|
-
expect(
|
|
42
|
-
expect(tf.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
await
|
|
42
|
+
(0, globals_1.describe)("Table create", () => {
|
|
43
|
+
(0, globals_1.it)("should create", async () => {
|
|
44
|
+
const tc = await table_1.default.create("mytable1");
|
|
45
|
+
const tf = await table_1.default.findOne({ id: tc.id });
|
|
46
|
+
(0, assertions_1.assertIsSet)(tf);
|
|
47
|
+
(0, globals_1.expect)(tf.external).toBe(false);
|
|
48
|
+
(0, globals_1.expect)(tc.external).toBe(false);
|
|
49
|
+
(0, globals_1.expect)(tf.name).toStrictEqual("mytable1");
|
|
50
|
+
(0, globals_1.expect)(tf.sql_name).toStrictEqual(db_1.default.isSQLite ? '"mytable1"' : '"public"."mytable1"');
|
|
51
|
+
});
|
|
52
|
+
(0, globals_1.it)("toggle bools", async () => {
|
|
53
|
+
const tc = await table_1.default.create("mytable17");
|
|
54
|
+
await field_1.default.create({
|
|
47
55
|
table: tc,
|
|
48
56
|
label: "Group",
|
|
49
57
|
type: "Bool",
|
|
@@ -52,12 +60,13 @@ describe("Table create", () => {
|
|
|
52
60
|
const tall_id = await tc.insertRow({ group: true });
|
|
53
61
|
await tc.toggleBool(tall_id, "group");
|
|
54
62
|
const row = await tc.getRow({ id: tall_id });
|
|
55
|
-
|
|
63
|
+
(0, assertions_1.assertIsSet)(row);
|
|
64
|
+
(0, globals_1.expect)(row.group).toBe(false);
|
|
56
65
|
});
|
|
57
|
-
it("should create required field in empty table without default", async () => {
|
|
58
|
-
const mytable1 = await
|
|
59
|
-
expect(!!mytable1).toBe(true);
|
|
60
|
-
await
|
|
66
|
+
(0, globals_1.it)("should create required field in empty table without default", async () => {
|
|
67
|
+
const mytable1 = await table_1.default.findOne({ name: "mytable1" });
|
|
68
|
+
(0, globals_1.expect)(!!mytable1).toBe(true);
|
|
69
|
+
await field_1.default.create({
|
|
61
70
|
table: mytable1,
|
|
62
71
|
name: "height1",
|
|
63
72
|
label: "height1",
|
|
@@ -65,86 +74,98 @@ describe("Table create", () => {
|
|
|
65
74
|
required: true,
|
|
66
75
|
});
|
|
67
76
|
});
|
|
68
|
-
it("should insert", async () => {
|
|
69
|
-
const mytable1 = await
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
expect(id
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
(0, globals_1.it)("should insert", async () => {
|
|
78
|
+
const mytable1 = await table_1.default.findOne({ name: "mytable1" });
|
|
79
|
+
(0, assertions_1.assertIsSet)(mytable1);
|
|
80
|
+
(0, globals_1.expect)(mytable1.name).toBe("mytable1");
|
|
81
|
+
const id = await db_1.default.insert(mytable1.name, { height1: 6 });
|
|
82
|
+
(0, globals_1.expect)(typeof id).toBe("number");
|
|
83
|
+
(0, globals_1.expect)(id > 0).toBe(true);
|
|
84
|
+
const row = await db_1.default.selectOne(mytable1.name, { id });
|
|
85
|
+
(0, globals_1.expect)(row.height1).toBe(6);
|
|
86
|
+
await db_1.default.update(mytable1.name, { height1: 7 }, id);
|
|
87
|
+
const rowup = await db_1.default.selectOne(mytable1.name, { id });
|
|
88
|
+
(0, globals_1.expect)(rowup.height1).toBe(7);
|
|
89
|
+
});
|
|
90
|
+
(0, globals_1.it)("should select one or zero", async () => {
|
|
91
|
+
const rows = await db_1.default.select("mytable1", {});
|
|
92
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
93
|
+
const row = await db_1.default.selectMaybeOne("mytable1", { id: rows[0].id });
|
|
94
|
+
(0, globals_1.expect)(row.height1).toBe(7);
|
|
95
|
+
const norow = await db_1.default.selectMaybeOne("mytable1", { id: 789 });
|
|
96
|
+
(0, globals_1.expect)(norow).toBe(null);
|
|
97
|
+
await (0, globals_1.expect)((async () => await db_1.default.selectOne("mytable1", { id: 789 }))()).rejects.toThrow();
|
|
98
|
+
});
|
|
99
|
+
(0, globals_1.it)("should get distinct values", async () => {
|
|
100
|
+
const table = await table_1.default.findOne({ name: "mytable1" });
|
|
101
|
+
(0, assertions_1.assertIsSet)(table);
|
|
91
102
|
const vs = await table.distinctValues("height1");
|
|
92
|
-
expect(vs).toEqual([7]);
|
|
103
|
+
(0, globals_1.expect)(vs).toEqual([7]);
|
|
93
104
|
});
|
|
94
|
-
it("should delete", async () => {
|
|
95
|
-
const table = await
|
|
105
|
+
(0, globals_1.it)("should delete", async () => {
|
|
106
|
+
const table = await table_1.default.findOne({ name: "mytable1" });
|
|
107
|
+
(0, assertions_1.assertIsSet)(table);
|
|
96
108
|
await table.delete();
|
|
97
|
-
const table1 = await
|
|
98
|
-
expect(table1.length).toBe(0);
|
|
109
|
+
const table1 = await table_1.default.find({ name: "mytable1" });
|
|
110
|
+
(0, globals_1.expect)(table1.length).toBe(0);
|
|
99
111
|
});
|
|
100
112
|
});
|
|
101
|
-
describe("Table get data", () => {
|
|
102
|
-
it("should get rows", async () => {
|
|
103
|
-
const patients = await
|
|
113
|
+
(0, globals_1.describe)("Table get data", () => {
|
|
114
|
+
(0, globals_1.it)("should get rows", async () => {
|
|
115
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
116
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
104
117
|
const all = await patients.getRows();
|
|
105
|
-
expect(all.length).toStrictEqual(2);
|
|
118
|
+
(0, globals_1.expect)(all.length).toStrictEqual(2);
|
|
106
119
|
});
|
|
107
|
-
it("should get rows where name is Michael", async () => {
|
|
108
|
-
const patients = await
|
|
120
|
+
(0, globals_1.it)("should get rows where name is Michael", async () => {
|
|
121
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
122
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
109
123
|
const michaels = await patients.getRows({ name: "Michael Douglas" });
|
|
110
|
-
|
|
124
|
+
(0, assertions_1.assertIsSet)(michaels);
|
|
125
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(1);
|
|
111
126
|
});
|
|
112
|
-
it("should get limited rows", async () => {
|
|
113
|
-
const patients = await
|
|
127
|
+
(0, globals_1.it)("should get limited rows", async () => {
|
|
128
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
129
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
114
130
|
const michaels = await patients.getRows({ name: { ilike: "Douglas" } }, { limit: 1, orderBy: "id", offset: 1 });
|
|
115
|
-
expect(michaels.length).toStrictEqual(1);
|
|
116
|
-
expect(michaels[0].name).toStrictEqual("Michael Douglas");
|
|
131
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(1);
|
|
132
|
+
(0, globals_1.expect)(michaels[0].name).toStrictEqual("Michael Douglas");
|
|
117
133
|
});
|
|
118
|
-
it("should get rows by slug", async () => {
|
|
119
|
-
const books = await
|
|
134
|
+
(0, globals_1.it)("should get rows by slug", async () => {
|
|
135
|
+
const books = await table_1.default.findOne({ name: "books" });
|
|
136
|
+
(0, assertions_1.assertIsSet)(books);
|
|
120
137
|
const all = await books.getRows({
|
|
121
138
|
author: { slugify: "herman-melville" },
|
|
122
139
|
});
|
|
123
|
-
expect(all.length).toStrictEqual(1);
|
|
124
|
-
expect(all[0].pages).toStrictEqual(967);
|
|
140
|
+
(0, globals_1.expect)(all.length).toStrictEqual(1);
|
|
141
|
+
(0, globals_1.expect)(all[0].pages).toStrictEqual(967);
|
|
125
142
|
});
|
|
126
|
-
it("should get joined rows where name is Michael", async () => {
|
|
127
|
-
const patients = await
|
|
143
|
+
(0, globals_1.it)("should get joined rows where name is Michael", async () => {
|
|
144
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
145
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
128
146
|
const michaels = await patients.getJoinedRows({
|
|
129
147
|
where: { name: "Michael Douglas" },
|
|
130
148
|
});
|
|
131
|
-
expect(michaels.length).toStrictEqual(1);
|
|
132
|
-
expect(michaels[0].favbook).toBe(2);
|
|
149
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(1);
|
|
150
|
+
(0, globals_1.expect)(michaels[0].favbook).toBe(2);
|
|
133
151
|
});
|
|
134
|
-
it("should get joined rows where name is not null", async () => {
|
|
135
|
-
const patients = await
|
|
152
|
+
(0, globals_1.it)("should get joined rows where name is not null", async () => {
|
|
153
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
154
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
136
155
|
const nameds = await patients.getJoinedRows({
|
|
137
156
|
where: { not: { name: null } },
|
|
138
157
|
});
|
|
139
|
-
expect(nameds.length).toStrictEqual(2);
|
|
158
|
+
(0, globals_1.expect)(nameds.length).toStrictEqual(2);
|
|
140
159
|
});
|
|
141
|
-
it("should get rows in id range", async () => {
|
|
142
|
-
const patients = await
|
|
160
|
+
(0, globals_1.it)("should get rows in id range", async () => {
|
|
161
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
162
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
143
163
|
const rows = await patients.getRows({ id: [{ gt: 0 }, { lt: 10 }] });
|
|
144
|
-
expect(rows.length).toStrictEqual(2);
|
|
164
|
+
(0, globals_1.expect)(rows.length).toStrictEqual(2);
|
|
145
165
|
});
|
|
146
|
-
it("should get rows by subselect", async () => {
|
|
147
|
-
const books = await
|
|
166
|
+
(0, globals_1.it)("should get rows by subselect", async () => {
|
|
167
|
+
const books = await table_1.default.findOne({ name: "books" });
|
|
168
|
+
(0, assertions_1.assertIsSet)(books);
|
|
148
169
|
const nrows = await books.countRows({
|
|
149
170
|
id: {
|
|
150
171
|
inSelect: {
|
|
@@ -154,29 +175,32 @@ describe("Table get data", () => {
|
|
|
154
175
|
},
|
|
155
176
|
},
|
|
156
177
|
});
|
|
157
|
-
expect(nrows).toStrictEqual(1);
|
|
178
|
+
(0, globals_1.expect)(nrows).toStrictEqual(1);
|
|
158
179
|
});
|
|
159
|
-
it("should get joined rows with limit and order", async () => {
|
|
160
|
-
const patients = await
|
|
180
|
+
(0, globals_1.it)("should get joined rows with limit and order", async () => {
|
|
181
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
182
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
161
183
|
const all = await patients.getJoinedRows({
|
|
162
184
|
limit: 2,
|
|
163
185
|
orderBy: "id",
|
|
164
186
|
});
|
|
165
|
-
expect(all.length).toStrictEqual(2);
|
|
166
|
-
expect(all[1].favbook).toBe(2);
|
|
187
|
+
(0, globals_1.expect)(all.length).toStrictEqual(2);
|
|
188
|
+
(0, globals_1.expect)(all[1].favbook).toBe(2);
|
|
167
189
|
});
|
|
168
|
-
it("should get joined rows with limit and desc order", async () => {
|
|
169
|
-
const patients = await
|
|
190
|
+
(0, globals_1.it)("should get joined rows with limit and desc order", async () => {
|
|
191
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
192
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
170
193
|
const all = await patients.getJoinedRows({
|
|
171
194
|
limit: 2,
|
|
172
195
|
orderBy: "id",
|
|
173
196
|
orderDesc: true,
|
|
174
197
|
});
|
|
175
|
-
expect(all.length).toStrictEqual(2);
|
|
176
|
-
expect(all[0].favbook).toBe(2);
|
|
198
|
+
(0, globals_1.expect)(all.length).toStrictEqual(2);
|
|
199
|
+
(0, globals_1.expect)(all[0].favbook).toBe(2);
|
|
177
200
|
});
|
|
178
|
-
it("should get joined rows with aggregations", async () => {
|
|
179
|
-
const patients = await
|
|
201
|
+
(0, globals_1.it)("should get joined rows with aggregations", async () => {
|
|
202
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
203
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
180
204
|
const michaels = await patients.getJoinedRows({
|
|
181
205
|
orderBy: "id",
|
|
182
206
|
aggregations: {
|
|
@@ -188,11 +212,12 @@ describe("Table get data", () => {
|
|
|
188
212
|
},
|
|
189
213
|
},
|
|
190
214
|
});
|
|
191
|
-
expect(michaels.length).toStrictEqual(2);
|
|
192
|
-
expect(Math.round(michaels[0].avg_temp)).toBe(38);
|
|
215
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(2);
|
|
216
|
+
(0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(38);
|
|
193
217
|
});
|
|
194
|
-
it("should get joined rows with latest aggregations", async () => {
|
|
195
|
-
const patients = await
|
|
218
|
+
(0, globals_1.it)("should get joined rows with latest aggregations", async () => {
|
|
219
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
220
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
196
221
|
const michaels = await patients.getJoinedRows({
|
|
197
222
|
orderBy: "id",
|
|
198
223
|
aggregations: {
|
|
@@ -204,22 +229,24 @@ describe("Table get data", () => {
|
|
|
204
229
|
},
|
|
205
230
|
},
|
|
206
231
|
});
|
|
207
|
-
expect(michaels.length).toStrictEqual(2);
|
|
208
|
-
expect(Math.round(michaels[0].last_temp)).toBe(37);
|
|
232
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(2);
|
|
233
|
+
(0, globals_1.expect)(Math.round(michaels[0].last_temp)).toBe(37);
|
|
209
234
|
});
|
|
210
|
-
it("should get double joined rows", async () => {
|
|
211
|
-
const readings = await
|
|
235
|
+
(0, globals_1.it)("should get double joined rows", async () => {
|
|
236
|
+
const readings = await table_1.default.findOne({ name: "readings" });
|
|
237
|
+
(0, assertions_1.assertIsSet)(readings);
|
|
212
238
|
const reads = await readings.getJoinedRows({
|
|
213
239
|
orderBy: "id",
|
|
214
240
|
joinFields: {
|
|
215
241
|
author: { ref: "patient_id", through: "favbook", target: "author" },
|
|
216
242
|
},
|
|
217
243
|
});
|
|
218
|
-
expect(reads.length).toStrictEqual(3);
|
|
219
|
-
expect(reads[0].author).toBe("Herman Melville");
|
|
244
|
+
(0, globals_1.expect)(reads.length).toStrictEqual(3);
|
|
245
|
+
(0, globals_1.expect)(reads[0].author).toBe("Herman Melville");
|
|
220
246
|
});
|
|
221
|
-
it("should get joined rows with aggregations and joins", async () => {
|
|
222
|
-
const patients = await
|
|
247
|
+
(0, globals_1.it)("should get joined rows with aggregations and joins", async () => {
|
|
248
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
249
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
223
250
|
const michaels = await patients.getJoinedRows({
|
|
224
251
|
orderBy: "id",
|
|
225
252
|
aggregations: {
|
|
@@ -235,54 +262,61 @@ describe("Table get data", () => {
|
|
|
235
262
|
author: { ref: "favbook", target: "author" },
|
|
236
263
|
},
|
|
237
264
|
});
|
|
238
|
-
expect(michaels.length).toStrictEqual(2);
|
|
239
|
-
expect(Math.round(michaels[0].avg_temp)).toBe(38);
|
|
240
|
-
expect(michaels[1].author).toBe("Leo Tolstoy");
|
|
265
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(2);
|
|
266
|
+
(0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(38);
|
|
267
|
+
(0, globals_1.expect)(michaels[1].author).toBe("Leo Tolstoy");
|
|
241
268
|
});
|
|
242
|
-
it("should support full text search", async () => {
|
|
243
|
-
const table = await
|
|
269
|
+
(0, globals_1.it)("should support full text search", async () => {
|
|
270
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
271
|
+
(0, assertions_1.assertIsSet)(table);
|
|
244
272
|
const fields = await table.getFields();
|
|
245
|
-
const rows = await
|
|
273
|
+
const rows = await db_1.default.select("patients", {
|
|
246
274
|
_fts: { fields, searchTerm: "Douglas" },
|
|
247
275
|
});
|
|
248
|
-
expect(rows.length).toBe(2);
|
|
276
|
+
(0, globals_1.expect)(rows.length).toBe(2);
|
|
249
277
|
});
|
|
250
|
-
it("should enable versioning", async () => {
|
|
251
|
-
const table = await
|
|
278
|
+
(0, globals_1.it)("should enable versioning", async () => {
|
|
279
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
280
|
+
(0, assertions_1.assertIsSet)(table);
|
|
252
281
|
table.versioned = true;
|
|
253
282
|
await table.update(table);
|
|
254
283
|
});
|
|
255
|
-
it("should save version on insert", async () => {
|
|
256
|
-
const table = await
|
|
284
|
+
(0, globals_1.it)("should save version on insert", async () => {
|
|
285
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
286
|
+
(0, assertions_1.assertIsSet)(table);
|
|
257
287
|
await table.insertRow({ name: "Bunny foo-foo", favbook: 1 });
|
|
258
288
|
const bunnyFooFoo = await table.getRow({ name: "Bunny foo-foo" });
|
|
289
|
+
(0, assertions_1.assertIsSet)(bunnyFooFoo);
|
|
259
290
|
const history1 = await table.get_history(bunnyFooFoo.id);
|
|
260
|
-
expect(history1.length).toBe(1);
|
|
261
|
-
expect(history1[0].id).toBe(bunnyFooFoo.id);
|
|
262
|
-
expect(history1[0]._version).toBe(1);
|
|
263
|
-
expect(history1[0].name).toBe("Bunny foo-foo");
|
|
264
|
-
});
|
|
265
|
-
it("should save version on update", async () => {
|
|
266
|
-
const table = await
|
|
291
|
+
(0, globals_1.expect)(history1.length).toBe(1);
|
|
292
|
+
(0, globals_1.expect)(history1[0].id).toBe(bunnyFooFoo.id);
|
|
293
|
+
(0, globals_1.expect)(history1[0]._version).toBe(1);
|
|
294
|
+
(0, globals_1.expect)(history1[0].name).toBe("Bunny foo-foo");
|
|
295
|
+
});
|
|
296
|
+
(0, globals_1.it)("should save version on update", async () => {
|
|
297
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
298
|
+
(0, assertions_1.assertIsSet)(table);
|
|
267
299
|
const bunnyFooFoo = await table.getRow({ name: "Bunny foo-foo" });
|
|
300
|
+
(0, assertions_1.assertIsSet)(bunnyFooFoo);
|
|
268
301
|
await table.updateRow({ name: "Goon" }, bunnyFooFoo.id);
|
|
269
302
|
const history2 = await table.get_history(bunnyFooFoo.id);
|
|
270
|
-
expect(history2.length).toBe(2);
|
|
271
|
-
expect(history2[0].id).toBe(bunnyFooFoo.id);
|
|
272
|
-
expect(history2[0]._version).toBe(1);
|
|
273
|
-
expect(history2[0].name).toBe("Bunny foo-foo");
|
|
274
|
-
expect(history2[0].favbook).toBe(1);
|
|
275
|
-
expect(history2[1].id).toBe(bunnyFooFoo.id);
|
|
276
|
-
expect(history2[1]._version).toBe(2);
|
|
277
|
-
expect(history2[1].name).toBe("Goon");
|
|
278
|
-
expect(history2[1].favbook).toBe(1);
|
|
303
|
+
(0, globals_1.expect)(history2.length).toBe(2);
|
|
304
|
+
(0, globals_1.expect)(history2[0].id).toBe(bunnyFooFoo.id);
|
|
305
|
+
(0, globals_1.expect)(history2[0]._version).toBe(1);
|
|
306
|
+
(0, globals_1.expect)(history2[0].name).toBe("Bunny foo-foo");
|
|
307
|
+
(0, globals_1.expect)(history2[0].favbook).toBe(1);
|
|
308
|
+
(0, globals_1.expect)(history2[1].id).toBe(bunnyFooFoo.id);
|
|
309
|
+
(0, globals_1.expect)(history2[1]._version).toBe(2);
|
|
310
|
+
(0, globals_1.expect)(history2[1].name).toBe("Goon");
|
|
311
|
+
(0, globals_1.expect)(history2[1].favbook).toBe(1);
|
|
279
312
|
const goon = await table.getRow({ id: bunnyFooFoo.id });
|
|
280
|
-
|
|
281
|
-
expect(goon.
|
|
313
|
+
(0, assertions_1.assertIsSet)(goon);
|
|
314
|
+
(0, globals_1.expect)(goon.name).toBe("Goon");
|
|
315
|
+
(0, globals_1.expect)(goon.favbook).toBe(1);
|
|
282
316
|
});
|
|
283
|
-
it("create field on version table", async () => {
|
|
284
|
-
const table = await
|
|
285
|
-
const fc = await
|
|
317
|
+
(0, globals_1.it)("create field on version table", async () => {
|
|
318
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
319
|
+
const fc = await field_1.default.create({
|
|
286
320
|
table: table,
|
|
287
321
|
name: "Height19",
|
|
288
322
|
label: "height19",
|
|
@@ -292,27 +326,28 @@ describe("Table get data", () => {
|
|
|
292
326
|
});
|
|
293
327
|
await fc.delete();
|
|
294
328
|
});
|
|
295
|
-
it("should disable versioning", async () => {
|
|
296
|
-
const table = await
|
|
329
|
+
(0, globals_1.it)("should disable versioning", async () => {
|
|
330
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
331
|
+
(0, assertions_1.assertIsSet)(table);
|
|
297
332
|
await table.getFields();
|
|
298
333
|
await table.update({ versioned: false });
|
|
299
334
|
});
|
|
300
|
-
it("should rename", async () => {
|
|
301
|
-
const table = await
|
|
302
|
-
await
|
|
335
|
+
(0, globals_1.it)("should rename", async () => {
|
|
336
|
+
const table = await table_1.default.create("notsurename");
|
|
337
|
+
await field_1.default.create({
|
|
303
338
|
table,
|
|
304
339
|
label: "tall",
|
|
305
340
|
type: "Bool",
|
|
306
341
|
required: true,
|
|
307
342
|
});
|
|
308
|
-
const table1 = await
|
|
309
|
-
await
|
|
343
|
+
const table1 = await table_1.default.create("refsunsure");
|
|
344
|
+
await field_1.default.create({
|
|
310
345
|
table: table1,
|
|
311
346
|
label: "also_tall",
|
|
312
347
|
type: "Bool",
|
|
313
348
|
required: true,
|
|
314
349
|
});
|
|
315
|
-
await
|
|
350
|
+
await field_1.default.create({
|
|
316
351
|
table: table1,
|
|
317
352
|
label: "theref",
|
|
318
353
|
type: "Key to notsurename",
|
|
@@ -322,23 +357,26 @@ describe("Table get data", () => {
|
|
|
322
357
|
await table1.insertRow({ also_tall: true, theref: id });
|
|
323
358
|
const joinFields = { reftall: { ref: "theref", target: "tall" } };
|
|
324
359
|
const rows = await table1.getJoinedRows({ joinFields });
|
|
325
|
-
expect(rows[0].theref).toBe(id);
|
|
326
|
-
expect(!!rows[0].reftall).toBe(false); //for sqlite
|
|
327
|
-
if (!
|
|
360
|
+
(0, globals_1.expect)(rows[0].theref).toBe(id);
|
|
361
|
+
(0, globals_1.expect)(!!rows[0].reftall).toBe(false); //for sqlite
|
|
362
|
+
if (!db_1.default.isSQLite) {
|
|
328
363
|
await table.rename("isthisbetter");
|
|
329
|
-
const table3 = await
|
|
364
|
+
const table3 = await table_1.default.findOne({ name: "refsunsure" });
|
|
365
|
+
(0, assertions_1.assertIsSet)(table3);
|
|
330
366
|
const rows1 = await table3.getJoinedRows({ joinFields });
|
|
331
|
-
expect(rows1[0].theref).toBe(id);
|
|
332
|
-
expect(rows1[0].reftall).toBe(false);
|
|
333
|
-
const table2 = await
|
|
334
|
-
|
|
367
|
+
(0, globals_1.expect)(rows1[0].theref).toBe(id);
|
|
368
|
+
(0, globals_1.expect)(rows1[0].reftall).toBe(false);
|
|
369
|
+
const table2 = await table_1.default.findOne({ name: "isthisbetter" });
|
|
370
|
+
(0, assertions_1.assertIsSet)(table2);
|
|
371
|
+
(0, globals_1.expect)(!!table2).toBe(true);
|
|
335
372
|
table2.versioned = true;
|
|
336
373
|
await table2.update(table2);
|
|
337
374
|
await table2.rename("thisisthebestname");
|
|
338
375
|
}
|
|
339
376
|
});
|
|
340
|
-
it("should get joined rows with arbitrary fieldnames", async () => {
|
|
341
|
-
const patients = await
|
|
377
|
+
(0, globals_1.it)("should get joined rows with arbitrary fieldnames", async () => {
|
|
378
|
+
const patients = await table_1.default.findOne({ name: "patients" });
|
|
379
|
+
(0, assertions_1.assertIsSet)(patients);
|
|
342
380
|
const michaels = await patients.getJoinedRows({
|
|
343
381
|
where: { name: "Michael Douglas" },
|
|
344
382
|
joinFields: {
|
|
@@ -346,27 +384,29 @@ describe("Table get data", () => {
|
|
|
346
384
|
author: { ref: "favbook", target: "author" },
|
|
347
385
|
},
|
|
348
386
|
});
|
|
349
|
-
expect(michaels.length).toStrictEqual(1);
|
|
350
|
-
expect(michaels[0].pages).toBe(728);
|
|
351
|
-
expect(michaels[0].author).toBe("Leo Tolstoy");
|
|
387
|
+
(0, globals_1.expect)(michaels.length).toStrictEqual(1);
|
|
388
|
+
(0, globals_1.expect)(michaels[0].pages).toBe(728);
|
|
389
|
+
(0, globals_1.expect)(michaels[0].author).toBe("Leo Tolstoy");
|
|
352
390
|
});
|
|
353
|
-
it("should get joined rows with one-to-one relations", async () => {
|
|
354
|
-
const ratings = await
|
|
355
|
-
|
|
391
|
+
(0, globals_1.it)("should get joined rows with one-to-one relations", async () => {
|
|
392
|
+
const ratings = await table_1.default.create("myreviews");
|
|
393
|
+
(0, assertions_1.assertIsSet)(ratings);
|
|
394
|
+
await field_1.default.create({
|
|
356
395
|
name: "book",
|
|
357
396
|
label: "Book",
|
|
358
397
|
type: "Key to books",
|
|
359
398
|
is_unique: true,
|
|
360
399
|
table: ratings,
|
|
361
400
|
});
|
|
362
|
-
await
|
|
401
|
+
await field_1.default.create({
|
|
363
402
|
name: "rating",
|
|
364
403
|
label: "Rating",
|
|
365
404
|
type: "Integer",
|
|
366
405
|
table: ratings,
|
|
367
406
|
});
|
|
368
407
|
await ratings.insertRow({ book: 1, rating: 7 });
|
|
369
|
-
const books = await
|
|
408
|
+
const books = await table_1.default.findOne({ name: "books" });
|
|
409
|
+
(0, assertions_1.assertIsSet)(books);
|
|
370
410
|
//db.set_sql_logging();
|
|
371
411
|
const reads = await books.getJoinedRows({
|
|
372
412
|
orderBy: "id",
|
|
@@ -375,42 +415,46 @@ describe("Table get data", () => {
|
|
|
375
415
|
rating: { ref: "book", ontable: "myreviews", target: "rating" },
|
|
376
416
|
},
|
|
377
417
|
});
|
|
378
|
-
expect(reads.length).toStrictEqual(1);
|
|
379
|
-
expect(reads[0].rating).toBe(7);
|
|
380
|
-
expect(reads[0].author).toBe("Herman Melville");
|
|
381
|
-
expect(reads[0].pages).toBe(967);
|
|
418
|
+
(0, globals_1.expect)(reads.length).toStrictEqual(1);
|
|
419
|
+
(0, globals_1.expect)(reads[0].rating).toBe(7);
|
|
420
|
+
(0, globals_1.expect)(reads[0].author).toBe("Herman Melville");
|
|
421
|
+
(0, globals_1.expect)(reads[0].pages).toBe(967);
|
|
382
422
|
});
|
|
383
423
|
});
|
|
384
|
-
describe("relations", () => {
|
|
385
|
-
it("get parent relations", async () => {
|
|
386
|
-
const table = await
|
|
424
|
+
(0, globals_1.describe)("relations", () => {
|
|
425
|
+
(0, globals_1.it)("get parent relations", async () => {
|
|
426
|
+
const table = await table_1.default.findOne({ name: "patients" });
|
|
427
|
+
(0, assertions_1.assertIsSet)(table);
|
|
387
428
|
const rels = await table.get_parent_relations();
|
|
388
|
-
expect(rels.parent_field_list).toContain("favbook.author");
|
|
389
|
-
expect(rels.parent_relations.length).toBe(2);
|
|
429
|
+
(0, globals_1.expect)(rels.parent_field_list).toContain("favbook.author");
|
|
430
|
+
(0, globals_1.expect)(rels.parent_relations.length).toBe(2);
|
|
390
431
|
});
|
|
391
|
-
it("get parent relations with one-to-one", async () => {
|
|
392
|
-
const table = await
|
|
432
|
+
(0, globals_1.it)("get parent relations with one-to-one", async () => {
|
|
433
|
+
const table = await table_1.default.findOne({ name: "books" });
|
|
434
|
+
(0, assertions_1.assertIsSet)(table);
|
|
393
435
|
const rels = await table.get_parent_relations();
|
|
394
|
-
expect(rels.parent_field_list).toEqual([
|
|
436
|
+
(0, globals_1.expect)(rels.parent_field_list).toEqual([
|
|
395
437
|
"myreviews.book->book",
|
|
396
438
|
"myreviews.book->id",
|
|
397
439
|
"myreviews.book->rating",
|
|
398
440
|
]);
|
|
399
441
|
});
|
|
400
|
-
it("get child relations", async () => {
|
|
401
|
-
const table = await
|
|
442
|
+
(0, globals_1.it)("get child relations", async () => {
|
|
443
|
+
const table = await table_1.default.findOne({ name: "books" });
|
|
444
|
+
(0, assertions_1.assertIsSet)(table);
|
|
402
445
|
const rels = await table.get_child_relations();
|
|
403
|
-
expect(rels.child_field_list).toEqual([
|
|
446
|
+
(0, globals_1.expect)(rels.child_field_list).toEqual([
|
|
404
447
|
"discusses_books.book",
|
|
405
448
|
"myreviews.book",
|
|
406
449
|
"patients.favbook",
|
|
407
450
|
]);
|
|
408
|
-
expect(rels.child_relations.length).toBe(3);
|
|
451
|
+
(0, globals_1.expect)(rels.child_relations.length).toBe(3);
|
|
409
452
|
});
|
|
410
|
-
it("get grandparent relations", async () => {
|
|
411
|
-
const table = await
|
|
453
|
+
(0, globals_1.it)("get grandparent relations", async () => {
|
|
454
|
+
const table = await table_1.default.findOne({ name: "readings" });
|
|
455
|
+
(0, assertions_1.assertIsSet)(table);
|
|
412
456
|
const rels = await table.get_parent_relations(true);
|
|
413
|
-
expect(rels.parent_field_list).toEqual([
|
|
457
|
+
(0, globals_1.expect)(rels.parent_field_list).toEqual([
|
|
414
458
|
"patient_id.favbook",
|
|
415
459
|
"patient_id.favbook.author",
|
|
416
460
|
"patient_id.favbook.id",
|
|
@@ -423,240 +467,266 @@ describe("relations", () => {
|
|
|
423
467
|
"patient_id.parent.name",
|
|
424
468
|
"patient_id.parent.parent",
|
|
425
469
|
]);
|
|
426
|
-
expect(rels.parent_relations.length).toBe(3);
|
|
470
|
+
(0, globals_1.expect)(rels.parent_relations.length).toBe(3);
|
|
427
471
|
});
|
|
428
472
|
});
|
|
429
|
-
describe("CSV import", () => {
|
|
430
|
-
it("should import into existing table", async () => {
|
|
473
|
+
(0, globals_1.describe)("CSV import", () => {
|
|
474
|
+
(0, globals_1.it)("should import into existing table", async () => {
|
|
431
475
|
const csv = `author,Pages
|
|
432
476
|
Joe Celko, 856
|
|
433
477
|
Gordon Kane, 217`;
|
|
434
478
|
const fnm = "/tmp/test1ok.csv";
|
|
435
|
-
await
|
|
436
|
-
const table = await
|
|
437
|
-
|
|
479
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
480
|
+
const table = await table_1.default.findOne({ name: "books" });
|
|
481
|
+
(0, assertions_1.assertIsSet)(table);
|
|
482
|
+
(0, globals_1.expect)(!!table).toBe(true);
|
|
438
483
|
const impres = await table.import_csv_file(fnm);
|
|
439
|
-
expect(impres).toEqual({ success: "Imported 2 rows into table books" });
|
|
484
|
+
(0, globals_1.expect)(impres).toEqual({ success: "Imported 2 rows into table books" });
|
|
440
485
|
const rows = await table.getRows({ author: "Gordon Kane" });
|
|
441
|
-
expect(rows.length).toBe(1);
|
|
442
|
-
expect(rows[0].pages).toBe(217);
|
|
486
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
487
|
+
(0, globals_1.expect)(rows[0].pages).toBe(217);
|
|
443
488
|
});
|
|
444
|
-
it("fail on required field", async () => {
|
|
489
|
+
(0, globals_1.it)("fail on required field", async () => {
|
|
445
490
|
const csv = `author,Pagez
|
|
446
491
|
Joe Celko, 856
|
|
447
492
|
Gordon Kane, 217`;
|
|
448
493
|
const fnm = "/tmp/test1f.csv";
|
|
449
|
-
await
|
|
450
|
-
const table = await
|
|
451
|
-
|
|
494
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
495
|
+
const table = await table_1.default.findOne({ name: "books" });
|
|
496
|
+
(0, assertions_1.assertIsSet)(table);
|
|
497
|
+
(0, globals_1.expect)(!!table).toBe(true);
|
|
452
498
|
const impres = await table.import_csv_file(fnm);
|
|
453
|
-
expect(impres).toEqual({ error: "Required field missing: Pages" });
|
|
499
|
+
(0, globals_1.expect)(impres).toEqual({ error: "Required field missing: Pages" });
|
|
454
500
|
});
|
|
455
|
-
it("fail on strings in ints", async () => {
|
|
501
|
+
(0, globals_1.it)("fail on strings in ints", async () => {
|
|
456
502
|
const csv = `author,Pages
|
|
457
503
|
Leonardo Boff, 99
|
|
458
504
|
David MacKay, ITILA`;
|
|
459
505
|
const fnm = "/tmp/test1.csv";
|
|
460
|
-
await
|
|
461
|
-
const table = await
|
|
506
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
507
|
+
const table = await table_1.default.create("books_not_req_pages", {
|
|
462
508
|
min_role_read: 10,
|
|
463
509
|
});
|
|
464
|
-
await
|
|
510
|
+
await field_1.default.create({
|
|
465
511
|
table,
|
|
466
512
|
name: "author",
|
|
467
513
|
label: "Author",
|
|
468
514
|
type: "String",
|
|
469
515
|
required: true,
|
|
470
516
|
});
|
|
471
|
-
await
|
|
517
|
+
await field_1.default.create({
|
|
472
518
|
table,
|
|
473
519
|
name: "pages",
|
|
474
520
|
label: "Pages",
|
|
475
521
|
type: "Integer",
|
|
476
522
|
attributes: { min: 0 },
|
|
477
523
|
});
|
|
478
|
-
expect(!!table).toBe(true);
|
|
524
|
+
(0, globals_1.expect)(!!table).toBe(true);
|
|
479
525
|
const impres = await table.import_csv_file(fnm);
|
|
480
|
-
expect(impres).toEqual({
|
|
526
|
+
(0, globals_1.expect)(impres).toEqual({
|
|
481
527
|
success: "Imported 1 rows into table books_not_req_pages. Rejected 1 rows.",
|
|
482
528
|
});
|
|
483
529
|
const rows = await table.getRows({ author: "David MacKay" });
|
|
484
|
-
expect(rows.length).toBe(0);
|
|
530
|
+
(0, globals_1.expect)(rows.length).toBe(0);
|
|
485
531
|
});
|
|
486
|
-
it("should create by importing", async () => {
|
|
532
|
+
(0, globals_1.it)("should create by importing", async () => {
|
|
487
533
|
//db.set_sql_logging();
|
|
488
534
|
const csv = `item,cost,count, vatable
|
|
489
535
|
Book, 5,4, f
|
|
490
536
|
Pencil, 0.5,2, t`;
|
|
491
537
|
const fnm = "/tmp/test2impok.csv";
|
|
492
|
-
await
|
|
493
|
-
const
|
|
538
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
539
|
+
const result = await table_1.default.create_from_csv("Invoice", fnm);
|
|
540
|
+
(0, assertions_1.assertsIsSuccessMessage)(result);
|
|
541
|
+
const { table } = result;
|
|
542
|
+
(0, assertions_1.assertIsSet)(table);
|
|
494
543
|
const fields = await table.getFields();
|
|
495
544
|
const vatField = fields.find((f) => f.name === "vatable");
|
|
496
|
-
|
|
545
|
+
(0, assertions_1.assertIsSet)(vatField);
|
|
546
|
+
(0, assertions_1.assertIsType)(vatField.type);
|
|
547
|
+
(0, globals_1.expect)(vatField.type.name).toBe("Bool");
|
|
497
548
|
const costField = fields.find((f) => f.name === "cost");
|
|
498
|
-
|
|
549
|
+
(0, assertions_1.assertIsSet)(costField);
|
|
550
|
+
(0, assertions_1.assertIsType)(costField.type);
|
|
551
|
+
(0, globals_1.expect)(costField.type.name).toBe("Float");
|
|
499
552
|
const countField = fields.find((f) => f.name === "count");
|
|
500
|
-
|
|
553
|
+
(0, assertions_1.assertIsSet)(countField);
|
|
554
|
+
(0, assertions_1.assertIsType)(countField.type);
|
|
555
|
+
(0, globals_1.expect)(countField.type.name).toBe("Integer");
|
|
501
556
|
const rows = await table.getRows({ item: "Pencil" });
|
|
502
|
-
expect(rows.length).toBe(1);
|
|
503
|
-
expect(rows[0].vatable).toBe(true);
|
|
557
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
558
|
+
(0, globals_1.expect)(rows[0].vatable).toBe(true);
|
|
504
559
|
const allrows = await table.getRows();
|
|
505
|
-
expect(allrows.length).toBe(2);
|
|
560
|
+
(0, globals_1.expect)(allrows.length).toBe(2);
|
|
506
561
|
});
|
|
507
|
-
it("should fail on bad col nm", async () => {
|
|
562
|
+
(0, globals_1.it)("should fail on bad col nm", async () => {
|
|
508
563
|
const csv = `item,cost,!, vatable
|
|
509
564
|
Book, 5,4, f
|
|
510
565
|
Pencil, 0.5,2, t`;
|
|
511
566
|
const fnm = "/tmp/test2.csv";
|
|
512
|
-
await
|
|
513
|
-
const res = await
|
|
514
|
-
expect(res).toEqual({
|
|
567
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
568
|
+
const res = await table_1.default.create_from_csv("Invoice1", fnm);
|
|
569
|
+
(0, globals_1.expect)(res).toEqual({
|
|
515
570
|
error: "Invalid column name ! - Use A-Z, a-z, 0-9, _ only",
|
|
516
571
|
});
|
|
517
|
-
const table = await
|
|
518
|
-
expect(table).toBe(null);
|
|
572
|
+
const table = await table_1.default.findOne({ name: "Invoice1" });
|
|
573
|
+
(0, globals_1.expect)(table).toBe(null);
|
|
519
574
|
});
|
|
520
|
-
it("ignores a col on duplicate col nm", async () => {
|
|
575
|
+
(0, globals_1.it)("ignores a col on duplicate col nm", async () => {
|
|
521
576
|
const csv = `item,cost,cost, vatable
|
|
522
577
|
Book, 5,4, f
|
|
523
578
|
Pencil, 0.5,2, t`;
|
|
524
579
|
const fnm = "/tmp/test2.csv";
|
|
525
|
-
await
|
|
526
|
-
const res = await
|
|
527
|
-
|
|
580
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
581
|
+
const res = await table_1.default.create_from_csv("Invoice1", fnm);
|
|
582
|
+
(0, assertions_1.assertsIsSuccessMessage)(res);
|
|
583
|
+
(0, globals_1.expect)(res.table.fields.length).toEqual(4); //and id
|
|
528
584
|
});
|
|
529
|
-
it("should fail non-int id", async () => {
|
|
585
|
+
(0, globals_1.it)("should fail non-int id", async () => {
|
|
530
586
|
const csv = `id,cost,!, vatable
|
|
531
587
|
Book, 5,4, f
|
|
532
588
|
Pencil, 0.5,2, t`;
|
|
533
589
|
const fnm = "/tmp/test2.csv";
|
|
534
|
-
await
|
|
535
|
-
const res = await
|
|
536
|
-
expect(res).toEqual({
|
|
590
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
591
|
+
const res = await table_1.default.create_from_csv("Invoice2", fnm);
|
|
592
|
+
(0, globals_1.expect)(res).toEqual({
|
|
537
593
|
error: `Columns named "id" must have only integers`,
|
|
538
594
|
});
|
|
539
|
-
const table = await
|
|
540
|
-
expect(table).toBe(null);
|
|
595
|
+
const table = await table_1.default.findOne({ name: "Invoice2" });
|
|
596
|
+
(0, globals_1.expect)(table).toBe(null);
|
|
541
597
|
});
|
|
542
|
-
it("should fail missing id", async () => {
|
|
598
|
+
(0, globals_1.it)("should fail missing id", async () => {
|
|
543
599
|
const csv = `id,cost,!, vatable
|
|
544
600
|
1, 5,4, f
|
|
545
601
|
, 0.5,2, t`;
|
|
546
602
|
const fnm = "/tmp/test2.csv";
|
|
547
|
-
await
|
|
548
|
-
const res = await
|
|
549
|
-
expect(res).toEqual({
|
|
603
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
604
|
+
const res = await table_1.default.create_from_csv("Invoice3", fnm);
|
|
605
|
+
(0, globals_1.expect)(res).toEqual({
|
|
550
606
|
error: `Columns named "id" must not have missing values`,
|
|
551
607
|
});
|
|
552
|
-
const table = await
|
|
553
|
-
expect(table).toBe(null);
|
|
608
|
+
const table = await table_1.default.findOne({ name: "Invoice3" });
|
|
609
|
+
(0, globals_1.expect)(table).toBe(null);
|
|
554
610
|
});
|
|
555
|
-
it("should succeed on good id", async () => {
|
|
611
|
+
(0, globals_1.it)("should succeed on good id", async () => {
|
|
556
612
|
const csv = `id,cost,count, vatable
|
|
557
613
|
1, 5,4, f
|
|
558
614
|
2, 0.5,2, t`;
|
|
559
615
|
const fnm = "/tmp/test2.csv";
|
|
560
|
-
await
|
|
561
|
-
const res = await
|
|
562
|
-
|
|
563
|
-
|
|
616
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
617
|
+
const res = await table_1.default.create_from_csv("Invoice3", fnm);
|
|
618
|
+
(0, assertions_1.assertsIsSuccessMessage)(res);
|
|
619
|
+
(0, globals_1.expect)(res.table.fields.length).toEqual(4); // incl id
|
|
620
|
+
const table = await table_1.default.findOne({ name: "Invoice3" });
|
|
621
|
+
(0, assertions_1.assertIsSet)(table);
|
|
564
622
|
const rows = await table.getRows();
|
|
565
|
-
expect(rows.length).toBe(2);
|
|
623
|
+
(0, globals_1.expect)(rows.length).toBe(2);
|
|
566
624
|
await table.insertRow({ cost: 0.2, count: 1, vatable: true });
|
|
567
625
|
const rows3 = await table.getRows();
|
|
568
|
-
expect(rows3.length).toBe(3);
|
|
626
|
+
(0, globals_1.expect)(rows3.length).toBe(3);
|
|
569
627
|
});
|
|
570
|
-
it("should fail on repeat id", async () => {
|
|
628
|
+
(0, globals_1.it)("should fail on repeat id", async () => {
|
|
571
629
|
const csv = `id,cost,count, vatable
|
|
572
630
|
1, 5,4, f
|
|
573
631
|
1, 0.5,2, t`;
|
|
574
632
|
const fnm = "/tmp/test2.csv";
|
|
575
|
-
await
|
|
576
|
-
const res = await
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
633
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
634
|
+
const res = await table_1.default.create_from_csv("Invoice4", fnm);
|
|
635
|
+
(0, assertions_1.assertIsErrorMsg)(res);
|
|
636
|
+
(0, globals_1.expect)(res.error).toContain("Invoice4");
|
|
637
|
+
const table = await table_1.default.findOne({ name: "Invoice4" });
|
|
638
|
+
(0, globals_1.expect)(table).toBe(null);
|
|
639
|
+
});
|
|
640
|
+
(0, globals_1.it)("should import with missing", async () => {
|
|
582
641
|
const csv = `item,cost,count, vatable
|
|
583
642
|
Book, 5,4, f
|
|
584
643
|
Pencil, 0.5,, t`;
|
|
585
644
|
const fnm = "/tmp/test2.csv";
|
|
586
|
-
await
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
645
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
646
|
+
const result = await table_1.default.create_from_csv("InvoiceMissing", fnm);
|
|
647
|
+
(0, assertions_1.assertsIsSuccessMessage)(result);
|
|
648
|
+
const { table } = result;
|
|
649
|
+
(0, assertions_1.assertIsSet)(table);
|
|
650
|
+
(0, globals_1.expect)(!!table).toBe(true);
|
|
590
651
|
const fields = await table.getFields();
|
|
591
652
|
const countField = fields.find((f) => f.name === "count");
|
|
592
|
-
|
|
593
|
-
|
|
653
|
+
(0, assertions_1.assertIsSet)(countField);
|
|
654
|
+
(0, assertions_1.assertIsType)(countField.type);
|
|
655
|
+
(0, globals_1.expect)(countField.type.name).toBe("Integer");
|
|
656
|
+
(0, globals_1.expect)(countField.required).toBe(false);
|
|
594
657
|
const rows = await table.getRows({ item: "Pencil" });
|
|
595
|
-
expect(rows.length).toBe(1);
|
|
596
|
-
expect(rows[0].count).toBe(null);
|
|
658
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
659
|
+
(0, globals_1.expect)(rows[0].count).toBe(null);
|
|
597
660
|
const brows = await table.getRows({ item: "Book" });
|
|
598
|
-
expect(brows[0].count).toBe(4);
|
|
661
|
+
(0, globals_1.expect)(brows[0].count).toBe(4);
|
|
599
662
|
});
|
|
600
|
-
it("should import with space in name", async () => {
|
|
663
|
+
(0, globals_1.it)("should import with space in name", async () => {
|
|
601
664
|
//db.set_sql_logging();
|
|
602
665
|
const csv = `Item Name,cost,count, vatable
|
|
603
666
|
Book, 5,4, f
|
|
604
667
|
Pencil, 0.5,2, t`;
|
|
605
668
|
const fnm = "/tmp/test2impok.csv";
|
|
606
|
-
await
|
|
607
|
-
const
|
|
669
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
670
|
+
const result = await table_1.default.create_from_csv("Invoice5", fnm);
|
|
671
|
+
(0, assertions_1.assertsIsSuccessMessage)(result);
|
|
672
|
+
const { table } = result;
|
|
608
673
|
const fields = await table.getFields();
|
|
609
674
|
const nameField = fields.find((f) => f.name === "item_name");
|
|
610
|
-
expect(nameField.type.name).toBe("String");
|
|
611
|
-
expect(nameField.label).toBe("Item Name");
|
|
675
|
+
(0, globals_1.expect)(nameField.type.name).toBe("String");
|
|
676
|
+
(0, globals_1.expect)(nameField.label).toBe("Item Name");
|
|
612
677
|
const allrows = await table.getRows();
|
|
613
|
-
expect(allrows.length).toBe(2);
|
|
678
|
+
(0, globals_1.expect)(allrows.length).toBe(2);
|
|
614
679
|
});
|
|
615
|
-
it("should import with underscore in name", async () => {
|
|
680
|
+
(0, globals_1.it)("should import with underscore in name", async () => {
|
|
616
681
|
//db.set_sql_logging();
|
|
617
682
|
const csv = `Item_Name,cost,count, vatable
|
|
618
683
|
Book, 5,4, f
|
|
619
684
|
Pencil, 0.5,2, t`;
|
|
620
685
|
const fnm = "/tmp/test2impok.csv";
|
|
621
|
-
await
|
|
622
|
-
const
|
|
686
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
687
|
+
const result = await table_1.default.create_from_csv("Invoice6", fnm);
|
|
688
|
+
(0, assertions_1.assertsIsSuccessMessage)(result);
|
|
689
|
+
const { table } = result;
|
|
623
690
|
const fields = await table.getFields();
|
|
624
|
-
expect(fields.map((f) => f.name)).toContain("item_name");
|
|
691
|
+
(0, globals_1.expect)(fields.map((f) => f.name)).toContain("item_name");
|
|
625
692
|
const nameField = fields.find((f) => f.name === "item_name");
|
|
626
|
-
expect(nameField.type.name).toBe("String");
|
|
627
|
-
expect(nameField.label).toBe("Item Name");
|
|
693
|
+
(0, globals_1.expect)(nameField.type.name).toBe("String");
|
|
694
|
+
(0, globals_1.expect)(nameField.label).toBe("Item Name");
|
|
628
695
|
const allrows = await table.getRows();
|
|
629
|
-
expect(allrows.length).toBe(2);
|
|
696
|
+
(0, globals_1.expect)(allrows.length).toBe(2);
|
|
630
697
|
});
|
|
631
698
|
});
|
|
632
|
-
describe("Table field uppercase", () => {
|
|
633
|
-
it("should create by importing", async () => {
|
|
699
|
+
(0, globals_1.describe)("Table field uppercase", () => {
|
|
700
|
+
(0, globals_1.it)("should create by importing", async () => {
|
|
634
701
|
const csv = `Item,cost,Count,Vatable
|
|
635
702
|
Book, 5,4, f
|
|
636
703
|
Pencil, 0.5,2, t`;
|
|
637
704
|
const fnm = "/tmp/test_uc.csv";
|
|
638
|
-
await
|
|
639
|
-
const
|
|
705
|
+
await (0, promises_1.writeFile)(fnm, csv);
|
|
706
|
+
const result = await table_1.default.create_from_csv("InvoiceUC", fnm);
|
|
707
|
+
(0, assertions_1.assertsIsSuccessMessage)(result);
|
|
708
|
+
const { table } = result;
|
|
709
|
+
(0, assertions_1.assertIsSet)(table);
|
|
640
710
|
const fields = await table.getFields();
|
|
641
711
|
const rows1 = await table.getJoinedRows({
|
|
642
712
|
where: { item: { ilike: "East" } },
|
|
643
713
|
});
|
|
644
|
-
expect(rows1.length).toBe(0);
|
|
714
|
+
(0, globals_1.expect)(rows1.length).toBe(0);
|
|
645
715
|
const rows2 = await table.getJoinedRows({
|
|
646
716
|
where: { count: 2 },
|
|
647
717
|
});
|
|
648
|
-
expect(rows2.length).toBe(1);
|
|
718
|
+
(0, globals_1.expect)(rows2.length).toBe(1);
|
|
649
719
|
const rows3 = await table.getJoinedRows({
|
|
650
720
|
where: { _fts: { searchTerm: "Book", fields } },
|
|
651
721
|
});
|
|
652
|
-
expect(rows3.length).toBe(1);
|
|
722
|
+
(0, globals_1.expect)(rows3.length).toBe(1);
|
|
653
723
|
});
|
|
654
724
|
});
|
|
655
|
-
describe("Table unique constraint", () => {
|
|
656
|
-
it("should create table", async () => {
|
|
725
|
+
(0, globals_1.describe)("Table unique constraint", () => {
|
|
726
|
+
(0, globals_1.it)("should create table", async () => {
|
|
657
727
|
//db.set_sql_logging()
|
|
658
|
-
const table = await
|
|
659
|
-
const field = await
|
|
728
|
+
const table = await table_1.default.create("TableWithUniques");
|
|
729
|
+
const field = await field_1.default.create({
|
|
660
730
|
table,
|
|
661
731
|
name: "name",
|
|
662
732
|
type: "String",
|
|
@@ -665,38 +735,40 @@ describe("Table unique constraint", () => {
|
|
|
665
735
|
await table.insertRow({ name: "Bill" });
|
|
666
736
|
const ted_id = await table.insertRow({ name: "Ted" });
|
|
667
737
|
const ins_res = await table.tryInsertRow({ name: "Bill" });
|
|
668
|
-
expect(ins_res).toEqual({
|
|
738
|
+
(0, globals_1.expect)(ins_res).toEqual({
|
|
669
739
|
error: "Duplicate value for unique field: name",
|
|
670
740
|
});
|
|
671
741
|
const ins_res1 = await table.tryInsertRow({ name: "Billy" });
|
|
672
|
-
|
|
742
|
+
(0, assertions_1.assertsIsSuccessMessage)(ins_res1);
|
|
743
|
+
(0, globals_1.expect)(typeof ins_res1.success).toEqual("number");
|
|
673
744
|
const upd_res = await table.tryUpdateRow({ name: "Bill" }, ted_id);
|
|
674
|
-
expect(upd_res).toEqual({
|
|
745
|
+
(0, globals_1.expect)(upd_res).toEqual({
|
|
675
746
|
error: "Duplicate value for unique field: name",
|
|
676
747
|
});
|
|
677
748
|
const upd_res1 = await table.tryUpdateRow({ name: "teddy" }, ted_id);
|
|
678
|
-
|
|
749
|
+
(0, assertions_1.assertsIsSuccessMessage)(upd_res1);
|
|
750
|
+
(0, globals_1.expect)(upd_res1.success).toEqual(true);
|
|
679
751
|
await field.update({ is_unique: false });
|
|
680
|
-
const field1 = await
|
|
681
|
-
expect(field1.is_unique).toBe(false);
|
|
752
|
+
const field1 = await field_1.default.findOne({ id: field.id });
|
|
753
|
+
(0, globals_1.expect)(field1.is_unique).toBe(false);
|
|
682
754
|
//const bill2_id = await table.insertRow({ name: "Bill" });
|
|
683
755
|
await field1.update({ is_unique: true });
|
|
684
|
-
const field2 = await
|
|
685
|
-
expect(field2.is_unique).toBe(true);
|
|
686
|
-
expect(field1.is_unique).toBe(true);
|
|
756
|
+
const field2 = await field_1.default.findOne({ id: field.id });
|
|
757
|
+
(0, globals_1.expect)(field2.is_unique).toBe(true);
|
|
758
|
+
(0, globals_1.expect)(field1.is_unique).toBe(true);
|
|
687
759
|
});
|
|
688
760
|
});
|
|
689
|
-
describe("Table not null constraint", () => {
|
|
690
|
-
it("should create table", async () => {
|
|
761
|
+
(0, globals_1.describe)("Table not null constraint", () => {
|
|
762
|
+
(0, globals_1.it)("should create table", async () => {
|
|
691
763
|
//db.set_sql_logging()
|
|
692
|
-
const table = await
|
|
693
|
-
const field = await
|
|
764
|
+
const table = await table_1.default.create("TableWithNotNulls");
|
|
765
|
+
const field = await field_1.default.create({
|
|
694
766
|
table,
|
|
695
767
|
name: "name",
|
|
696
768
|
type: "String",
|
|
697
769
|
required: true,
|
|
698
770
|
});
|
|
699
|
-
await
|
|
771
|
+
await field_1.default.create({
|
|
700
772
|
table,
|
|
701
773
|
name: "age",
|
|
702
774
|
type: "Integer",
|
|
@@ -704,70 +776,73 @@ describe("Table not null constraint", () => {
|
|
|
704
776
|
await table.insertRow({ name: "Bill", age: 13 });
|
|
705
777
|
await table.insertRow({ name: "Bill", age: 13 });
|
|
706
778
|
const ins_res = await table.tryInsertRow({ age: 17, name: null });
|
|
707
|
-
|
|
708
|
-
expect(ins_res.error).
|
|
709
|
-
|
|
779
|
+
(0, assertions_1.assertIsErrorMsg)(ins_res);
|
|
780
|
+
(0, globals_1.expect)(!!ins_res.error).toBe(true);
|
|
781
|
+
(0, globals_1.expect)(ins_res.error).toContain("name");
|
|
782
|
+
if (!db_1.default.isSQLite) {
|
|
710
783
|
await field.update({ required: false });
|
|
711
784
|
const ted_id = await table.insertRow({ age: 17 });
|
|
712
785
|
await table.deleteRows({ id: ted_id });
|
|
713
786
|
await field.update({ required: true });
|
|
714
787
|
const ins_res1 = await table.tryInsertRow({ age: 167 });
|
|
715
|
-
|
|
788
|
+
(0, assertions_1.assertIsErrorMsg)(ins_res1);
|
|
789
|
+
(0, globals_1.expect)(!!ins_res1.error).toBe(true);
|
|
716
790
|
}
|
|
717
791
|
});
|
|
718
|
-
it("should query null", async () => {
|
|
719
|
-
const table = await
|
|
792
|
+
(0, globals_1.it)("should query null", async () => {
|
|
793
|
+
const table = await table_1.default.findOne({ name: "TableWithNotNulls" });
|
|
794
|
+
(0, assertions_1.assertIsSet)(table);
|
|
720
795
|
await table.insertRow({ name: "Ageless", age: null });
|
|
721
796
|
const rows = await table.getRows({ age: null });
|
|
722
|
-
expect(rows.length).toBe(1);
|
|
723
|
-
expect(rows[0].name).toBe("Ageless");
|
|
797
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
798
|
+
(0, globals_1.expect)(rows[0].name).toBe("Ageless");
|
|
724
799
|
const rows1 = await table.getRows({ age: null, name: "Ageless" });
|
|
725
|
-
expect(rows1.length).toBe(1);
|
|
726
|
-
expect(rows1[0].name).toBe("Ageless");
|
|
800
|
+
(0, globals_1.expect)(rows1.length).toBe(1);
|
|
801
|
+
(0, globals_1.expect)(rows1[0].name).toBe("Ageless");
|
|
727
802
|
const rows2 = await table.getRows({ name: "Ageless", age: null });
|
|
728
|
-
expect(rows2.length).toBe(1);
|
|
729
|
-
expect(rows2[0].name).toBe("Ageless");
|
|
803
|
+
(0, globals_1.expect)(rows2.length).toBe(1);
|
|
804
|
+
(0, globals_1.expect)(rows2[0].name).toBe("Ageless");
|
|
730
805
|
});
|
|
731
806
|
});
|
|
732
|
-
describe("Table with users and files", () => {
|
|
733
|
-
it("should create table", async () => {
|
|
807
|
+
(0, globals_1.describe)("Table with users and files", () => {
|
|
808
|
+
(0, globals_1.it)("should create table", async () => {
|
|
734
809
|
//db.set_sql_logging()
|
|
735
810
|
const rick = await rick_file();
|
|
736
|
-
const table = await
|
|
737
|
-
await
|
|
811
|
+
const table = await table_1.default.create("TableWithUsers");
|
|
812
|
+
await field_1.default.create({
|
|
738
813
|
table,
|
|
739
814
|
name: "name",
|
|
740
815
|
type: "String",
|
|
741
816
|
is_unique: true,
|
|
742
817
|
});
|
|
743
|
-
await
|
|
818
|
+
await field_1.default.create({
|
|
744
819
|
table,
|
|
745
820
|
name: "owner",
|
|
746
821
|
type: "Key to users",
|
|
747
822
|
});
|
|
748
|
-
await
|
|
823
|
+
await field_1.default.create({
|
|
749
824
|
table,
|
|
750
825
|
name: "mugshot",
|
|
751
826
|
type: "File",
|
|
752
827
|
});
|
|
753
828
|
await table.insertRow({ name: "Rocket", owner: 1, mugshot: rick.id });
|
|
754
829
|
const rels = await table.get_parent_relations();
|
|
755
|
-
expect(rels.parent_field_list).toEqual(["owner.email", "owner.id"]);
|
|
830
|
+
(0, globals_1.expect)(rels.parent_field_list).toEqual(["owner.email", "owner.id"]);
|
|
756
831
|
const joined = await table.getJoinedRows();
|
|
757
832
|
// expect(joined).toEqual("rick.png")
|
|
758
|
-
expect(joined[0].mugshot__filename).toEqual("rick.png");
|
|
833
|
+
(0, globals_1.expect)(joined[0].mugshot__filename).toEqual("rick.png");
|
|
759
834
|
});
|
|
760
835
|
});
|
|
761
|
-
describe("Table and view deletion ", () => {
|
|
762
|
-
it("should setup", async () => {
|
|
763
|
-
const tc = await
|
|
764
|
-
await
|
|
836
|
+
(0, globals_1.describe)("Table and view deletion ", () => {
|
|
837
|
+
(0, globals_1.it)("should setup", async () => {
|
|
838
|
+
const tc = await table_1.default.create("mytable19");
|
|
839
|
+
await field_1.default.create({
|
|
765
840
|
table: tc,
|
|
766
841
|
name: "name",
|
|
767
842
|
type: "String",
|
|
768
843
|
is_unique: true,
|
|
769
844
|
});
|
|
770
|
-
const v = await
|
|
845
|
+
const v = await view_1.default.create({
|
|
771
846
|
table_id: tc.id,
|
|
772
847
|
name: "anewview",
|
|
773
848
|
viewtemplate: "List",
|
|
@@ -784,17 +859,17 @@ describe("Table and view deletion ", () => {
|
|
|
784
859
|
//expect(error).toBeInstanceOf(Error); - not on SQLite
|
|
785
860
|
await v.delete();
|
|
786
861
|
});
|
|
787
|
-
it("should delete table after view delete", async () => {
|
|
788
|
-
const tc = await
|
|
862
|
+
(0, globals_1.it)("should delete table after view delete", async () => {
|
|
863
|
+
const tc = await table_1.default.findOne({ name: "mytable19" });
|
|
789
864
|
if (tc)
|
|
790
865
|
await tc.delete();
|
|
791
866
|
});
|
|
792
867
|
});
|
|
793
|
-
describe("Table with date", () => {
|
|
794
|
-
it("should create table", async () => {
|
|
868
|
+
(0, globals_1.describe)("Table with date", () => {
|
|
869
|
+
(0, globals_1.it)("should create table", async () => {
|
|
795
870
|
//db.set_sql_logging()
|
|
796
|
-
const table = await
|
|
797
|
-
await
|
|
871
|
+
const table = await table_1.default.create("TableWithDates");
|
|
872
|
+
await field_1.default.create({
|
|
798
873
|
table,
|
|
799
874
|
name: "time",
|
|
800
875
|
type: "Date",
|
|
@@ -802,25 +877,25 @@ describe("Table with date", () => {
|
|
|
802
877
|
await table.insertRow({ time: new Date() });
|
|
803
878
|
const rows = await table.getRows();
|
|
804
879
|
var dif = new Date(rows[0].time).getTime() - new Date().getTime();
|
|
805
|
-
expect(Math.abs(dif)).toBeLessThanOrEqual(1000);
|
|
880
|
+
(0, globals_1.expect)(Math.abs(dif)).toBeLessThanOrEqual(1000);
|
|
806
881
|
});
|
|
807
882
|
});
|
|
808
|
-
describe("Tables with name clashes", () => {
|
|
809
|
-
it("should create tables", async () => {
|
|
883
|
+
(0, globals_1.describe)("Tables with name clashes", () => {
|
|
884
|
+
(0, globals_1.it)("should create tables", async () => {
|
|
810
885
|
//db.set_sql_logging()
|
|
811
|
-
const cars = await
|
|
812
|
-
const persons = await
|
|
813
|
-
await
|
|
886
|
+
const cars = await table_1.default.create("TableClashCar");
|
|
887
|
+
const persons = await table_1.default.create("TableClashPerson");
|
|
888
|
+
await field_1.default.create({
|
|
814
889
|
table: persons,
|
|
815
890
|
name: "name",
|
|
816
891
|
type: "String",
|
|
817
892
|
});
|
|
818
|
-
await
|
|
893
|
+
await field_1.default.create({
|
|
819
894
|
table: cars,
|
|
820
895
|
name: "name",
|
|
821
896
|
type: "String",
|
|
822
897
|
});
|
|
823
|
-
await
|
|
898
|
+
await field_1.default.create({
|
|
824
899
|
table: cars,
|
|
825
900
|
name: "owner",
|
|
826
901
|
type: "Key to TableClashPerson",
|
|
@@ -828,23 +903,25 @@ describe("Tables with name clashes", () => {
|
|
|
828
903
|
const sally = await persons.insertRow({ name: "Sally" });
|
|
829
904
|
await cars.insertRow({ name: "Mustang", owner: sally });
|
|
830
905
|
});
|
|
831
|
-
it("should query", async () => {
|
|
832
|
-
const cars = await
|
|
906
|
+
(0, globals_1.it)("should query", async () => {
|
|
907
|
+
const cars = await table_1.default.findOne({ name: "TableClashCar" });
|
|
908
|
+
(0, assertions_1.assertIsSet)(cars);
|
|
833
909
|
const rows = await cars.getJoinedRows({
|
|
834
910
|
joinFields: {
|
|
835
911
|
owner_name: { ref: "owner", target: "name" },
|
|
836
912
|
},
|
|
837
913
|
});
|
|
838
|
-
expect(rows[0]).toEqual({
|
|
914
|
+
(0, globals_1.expect)(rows[0]).toEqual({
|
|
839
915
|
id: 1,
|
|
840
916
|
name: "Mustang",
|
|
841
917
|
owner: 1,
|
|
842
918
|
owner_name: "Sally",
|
|
843
919
|
});
|
|
844
920
|
});
|
|
845
|
-
it("should show list view", async () => {
|
|
846
|
-
const cars = await
|
|
847
|
-
|
|
921
|
+
(0, globals_1.it)("should show list view", async () => {
|
|
922
|
+
const cars = await table_1.default.findOne({ name: "TableClashCar" });
|
|
923
|
+
(0, assertions_1.assertIsSet)(cars);
|
|
924
|
+
const v = await view_1.default.create({
|
|
848
925
|
table_id: cars.id,
|
|
849
926
|
name: "patientlist",
|
|
850
927
|
viewtemplate: "List",
|
|
@@ -857,12 +934,13 @@ describe("Tables with name clashes", () => {
|
|
|
857
934
|
min_role: 10,
|
|
858
935
|
});
|
|
859
936
|
const res = await v.run({}, mockReqRes);
|
|
860
|
-
expect(res).toContain("Mustang");
|
|
861
|
-
expect(res).toContain("Sally");
|
|
937
|
+
(0, globals_1.expect)(res).toContain("Mustang");
|
|
938
|
+
(0, globals_1.expect)(res).toContain("Sally");
|
|
862
939
|
});
|
|
863
|
-
it("should show show view", async () => {
|
|
864
|
-
const cars = await
|
|
865
|
-
|
|
940
|
+
(0, globals_1.it)("should show show view", async () => {
|
|
941
|
+
const cars = await table_1.default.findOne({ name: "TableClashCar" });
|
|
942
|
+
(0, assertions_1.assertIsSet)(cars);
|
|
943
|
+
const v = await view_1.default.create({
|
|
866
944
|
table_id: cars.id,
|
|
867
945
|
name: "patientlist",
|
|
868
946
|
viewtemplate: "Show",
|
|
@@ -881,115 +959,123 @@ describe("Tables with name clashes", () => {
|
|
|
881
959
|
min_role: 10,
|
|
882
960
|
});
|
|
883
961
|
const res = await v.run({ id: 1 }, mockReqRes);
|
|
884
|
-
expect(res).toContain("Mustang");
|
|
885
|
-
expect(res).toContain("Sally");
|
|
962
|
+
(0, globals_1.expect)(res).toContain("Mustang");
|
|
963
|
+
(0, globals_1.expect)(res).toContain("Sally");
|
|
886
964
|
});
|
|
887
965
|
});
|
|
888
|
-
describe("Table joint unique constraint", () => {
|
|
889
|
-
it("should create table", async () => {
|
|
890
|
-
const table = await
|
|
966
|
+
(0, globals_1.describe)("Table joint unique constraint", () => {
|
|
967
|
+
(0, globals_1.it)("should create table", async () => {
|
|
968
|
+
const table = await table_1.default.findOne({ name: "books" });
|
|
969
|
+
(0, assertions_1.assertIsSet)(table);
|
|
970
|
+
(0, assertions_1.assertIsSet)(table.id);
|
|
891
971
|
const rows = await table.getRows();
|
|
892
972
|
const { id, ...row0 } = rows[0];
|
|
893
|
-
const tc = await
|
|
973
|
+
const tc = await table_constraints_1.default.create({
|
|
894
974
|
table_id: table.id,
|
|
895
975
|
type: "Unique",
|
|
896
976
|
configuration: { fields: ["author", "pages"] },
|
|
897
977
|
});
|
|
898
978
|
const res = await table.tryInsertRow(row0);
|
|
899
|
-
|
|
979
|
+
(0, assertions_1.assertIsErrorMsg)(res);
|
|
980
|
+
(0, globals_1.expect)(!!res.error).toBe(true);
|
|
900
981
|
await tc.delete();
|
|
901
982
|
const res1 = await table.tryInsertRow(row0);
|
|
902
|
-
|
|
983
|
+
(0, assertions_1.assertIsErrorMsg)(res1);
|
|
984
|
+
(0, globals_1.expect)(!!res1.error).toBe(false);
|
|
903
985
|
});
|
|
904
986
|
});
|
|
905
|
-
describe("Table with row ownership", () => {
|
|
906
|
-
it("should create and delete table", async () => {
|
|
907
|
-
const persons = await
|
|
908
|
-
const name = await
|
|
987
|
+
(0, globals_1.describe)("Table with row ownership", () => {
|
|
988
|
+
(0, globals_1.it)("should create and delete table", async () => {
|
|
989
|
+
const persons = await table_1.default.create("TableOwned");
|
|
990
|
+
const name = await field_1.default.create({
|
|
909
991
|
table: persons,
|
|
910
992
|
name: "name",
|
|
911
993
|
type: "String",
|
|
912
994
|
});
|
|
913
|
-
const age = await
|
|
995
|
+
const age = await field_1.default.create({
|
|
914
996
|
table: persons,
|
|
915
997
|
name: "age",
|
|
916
998
|
type: "String",
|
|
917
999
|
});
|
|
918
|
-
const owner = await
|
|
1000
|
+
const owner = await field_1.default.create({
|
|
919
1001
|
table: persons,
|
|
920
1002
|
name: "owner",
|
|
921
1003
|
type: "Key to users",
|
|
922
1004
|
});
|
|
923
1005
|
await persons.update({ ownership_field_id: owner.id });
|
|
924
|
-
if (!
|
|
1006
|
+
if (!db_1.default.isSQLite) {
|
|
925
1007
|
await age.update({ type: "Integer" });
|
|
926
1008
|
await name.update({ name: "lastname" });
|
|
927
1009
|
await persons.insertRow({ lastname: "Joe", age: 12 });
|
|
928
1010
|
await persons.insertRow({ lastname: "Sam", age: 13, owner: 1 });
|
|
929
1011
|
const row = await persons.getRow({ age: 12 });
|
|
930
|
-
|
|
931
|
-
expect(row.
|
|
1012
|
+
(0, assertions_1.assertIsSet)(row);
|
|
1013
|
+
(0, globals_1.expect)(row.lastname).toBe("Joe");
|
|
1014
|
+
(0, globals_1.expect)(row.age).toBe(12);
|
|
932
1015
|
const owner_fnm = await persons.owner_fieldname();
|
|
933
|
-
expect(owner_fnm).toBe("owner");
|
|
1016
|
+
(0, globals_1.expect)(owner_fnm).toBe("owner");
|
|
934
1017
|
const is_owner = await persons.is_owner({ id: 6 }, row);
|
|
935
|
-
expect(is_owner).toBe(false);
|
|
1018
|
+
(0, globals_1.expect)(is_owner).toBe(false);
|
|
936
1019
|
const row1 = await persons.getRow({ age: 13 });
|
|
1020
|
+
(0, assertions_1.assertIsSet)(row1);
|
|
937
1021
|
const is_owner1 = await persons.is_owner({ id: 1 }, row1);
|
|
938
|
-
expect(is_owner1).toBe(true);
|
|
1022
|
+
(0, globals_1.expect)(is_owner1).toBe(true);
|
|
939
1023
|
}
|
|
940
1024
|
await persons.delete();
|
|
941
1025
|
});
|
|
942
1026
|
});
|
|
943
|
-
describe("Table with row ownership", () => {
|
|
944
|
-
it("should create and delete table", async () => {
|
|
945
|
-
const persons = await
|
|
946
|
-
const name = await
|
|
1027
|
+
(0, globals_1.describe)("Table with row ownership", () => {
|
|
1028
|
+
(0, globals_1.it)("should create and delete table", async () => {
|
|
1029
|
+
const persons = await table_1.default.create("TableOwnedFml");
|
|
1030
|
+
const name = await field_1.default.create({
|
|
947
1031
|
table: persons,
|
|
948
1032
|
name: "name",
|
|
949
1033
|
type: "String",
|
|
950
1034
|
});
|
|
951
|
-
const age = await
|
|
1035
|
+
const age = await field_1.default.create({
|
|
952
1036
|
table: persons,
|
|
953
1037
|
name: "age",
|
|
954
1038
|
type: "String",
|
|
955
1039
|
});
|
|
956
|
-
const owner = await
|
|
1040
|
+
const owner = await field_1.default.create({
|
|
957
1041
|
table: persons,
|
|
958
1042
|
name: "owner",
|
|
959
1043
|
type: "Key to users",
|
|
960
1044
|
});
|
|
961
1045
|
await persons.update({ ownership_formula: "user.id===owner" });
|
|
962
|
-
if (!
|
|
1046
|
+
if (!db_1.default.isSQLite) {
|
|
963
1047
|
await age.update({ type: "Integer" });
|
|
964
1048
|
await name.update({ name: "lastname" });
|
|
965
1049
|
await persons.insertRow({ lastname: "Joe", age: 12 });
|
|
966
1050
|
await persons.insertRow({ lastname: "Sam", age: 13, owner: 1 });
|
|
967
1051
|
const row = await persons.getRow({ age: 12 });
|
|
968
|
-
|
|
969
|
-
expect(row.
|
|
1052
|
+
(0, assertions_1.assertIsSet)(row);
|
|
1053
|
+
(0, globals_1.expect)(row.lastname).toBe("Joe");
|
|
1054
|
+
(0, globals_1.expect)(row.age).toBe(12);
|
|
970
1055
|
const is_owner = await persons.is_owner({ id: 6 }, row);
|
|
971
|
-
expect(is_owner).toBe(false);
|
|
1056
|
+
(0, globals_1.expect)(is_owner).toBe(false);
|
|
972
1057
|
const row1 = await persons.getRow({ age: 13 });
|
|
1058
|
+
(0, assertions_1.assertIsSet)(row1);
|
|
973
1059
|
const is_owner1 = await persons.is_owner({ id: 1 }, row1);
|
|
974
|
-
expect(is_owner1).toBe(true);
|
|
1060
|
+
(0, globals_1.expect)(is_owner1).toBe(true);
|
|
975
1061
|
}
|
|
976
1062
|
await persons.delete();
|
|
977
1063
|
});
|
|
978
1064
|
});
|
|
979
|
-
describe("Table with UUID pks", () => {
|
|
980
|
-
if (!
|
|
981
|
-
it("should select uuid", async () => {
|
|
982
|
-
await
|
|
983
|
-
const { rows } = await
|
|
984
|
-
expect(rows.length).toBe(1);
|
|
985
|
-
expect(typeof rows[0].uuid_generate_v4).toBe("string");
|
|
986
|
-
});
|
|
987
|
-
it("should create and insert stuff in table", async () => {
|
|
1065
|
+
(0, globals_1.describe)("Table with UUID pks", () => {
|
|
1066
|
+
if (!db_1.default.isSQLite) {
|
|
1067
|
+
(0, globals_1.it)("should select uuid", async () => {
|
|
1068
|
+
await db_1.default.query('create extension if not exists "uuid-ossp";');
|
|
1069
|
+
const { rows } = await db_1.default.query("select uuid_generate_v4();");
|
|
1070
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
1071
|
+
(0, globals_1.expect)(typeof rows[0].uuid_generate_v4).toBe("string");
|
|
1072
|
+
});
|
|
1073
|
+
(0, globals_1.it)("should create and insert stuff in table", async () => {
|
|
988
1074
|
getState().registerPlugin("mock_plugin", plugin_with_routes);
|
|
989
|
-
const table = await
|
|
1075
|
+
const table = await table_1.default.create("TableUUID");
|
|
990
1076
|
const [pk] = await table.getFields();
|
|
991
1077
|
await pk.update({ type: "UUID" });
|
|
992
|
-
const name = await
|
|
1078
|
+
const name = await field_1.default.create({
|
|
993
1079
|
table: table,
|
|
994
1080
|
name: "name",
|
|
995
1081
|
type: "String",
|
|
@@ -997,44 +1083,47 @@ describe("Table with UUID pks", () => {
|
|
|
997
1083
|
table.fields = null;
|
|
998
1084
|
await table.insertRow({ name: "Sam" });
|
|
999
1085
|
const rows = await table.getRows();
|
|
1000
|
-
expect(rows.length).toBe(1);
|
|
1001
|
-
expect(typeof rows[0].id).toBe("string");
|
|
1002
|
-
expect(rows[0].id.length > 10).toBe(true);
|
|
1003
|
-
expect(rows[0].name).toBe("Sam");
|
|
1086
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
1087
|
+
(0, globals_1.expect)(typeof rows[0].id).toBe("string");
|
|
1088
|
+
(0, globals_1.expect)(rows[0].id.length > 10).toBe(true);
|
|
1089
|
+
(0, globals_1.expect)(rows[0].name).toBe("Sam");
|
|
1004
1090
|
await table.updateRow({ name: "Jim" }, rows[0].id);
|
|
1005
1091
|
const rows1 = await table.getJoinedRows();
|
|
1006
|
-
expect(rows1.length).toBe(1);
|
|
1007
|
-
expect(typeof rows1[0].id).toBe("string");
|
|
1008
|
-
expect(rows1[0].id).toBe(rows[0].id);
|
|
1009
|
-
expect(rows1[0].name).toBe("Jim");
|
|
1092
|
+
(0, globals_1.expect)(rows1.length).toBe(1);
|
|
1093
|
+
(0, globals_1.expect)(typeof rows1[0].id).toBe("string");
|
|
1094
|
+
(0, globals_1.expect)(rows1[0].id).toBe(rows[0].id);
|
|
1095
|
+
(0, globals_1.expect)(rows1[0].name).toBe("Jim");
|
|
1010
1096
|
const row = await table.getRow({ id: rows[0].id });
|
|
1011
|
-
|
|
1097
|
+
(0, assertions_1.assertIsSet)(row);
|
|
1098
|
+
(0, globals_1.expect)(row.name).toBe("Jim");
|
|
1012
1099
|
});
|
|
1013
|
-
it("should import json", async () => {
|
|
1100
|
+
(0, globals_1.it)("should import json", async () => {
|
|
1014
1101
|
const json = [
|
|
1015
1102
|
{ name: "Alex", id: "750d07fc-943d-4afc-9084-3911bcdbd0f7" },
|
|
1016
1103
|
];
|
|
1017
1104
|
const fnm = "/tmp/test1.json";
|
|
1018
|
-
await
|
|
1019
|
-
const table = await
|
|
1020
|
-
|
|
1105
|
+
await (0, promises_1.writeFile)(fnm, JSON.stringify(json));
|
|
1106
|
+
const table = await table_1.default.findOne({ name: "TableUUID" });
|
|
1107
|
+
(0, assertions_1.assertIsSet)(table);
|
|
1108
|
+
(0, globals_1.expect)(!!table).toBe(true);
|
|
1021
1109
|
const impres = await table.import_json_file(fnm);
|
|
1022
|
-
expect(impres).toEqual({
|
|
1110
|
+
(0, globals_1.expect)(impres).toEqual({
|
|
1023
1111
|
success: "Imported 1 rows into table TableUUID",
|
|
1024
1112
|
});
|
|
1025
1113
|
const rows = await table.getRows();
|
|
1026
|
-
expect(rows.length).toBe(2);
|
|
1114
|
+
(0, globals_1.expect)(rows.length).toBe(2);
|
|
1027
1115
|
});
|
|
1028
|
-
it("should be joinable to", async () => {
|
|
1029
|
-
const uuidtable1 = await
|
|
1030
|
-
|
|
1031
|
-
await
|
|
1116
|
+
(0, globals_1.it)("should be joinable to", async () => {
|
|
1117
|
+
const uuidtable1 = await table_1.default.findOne({ name: "TableUUID" });
|
|
1118
|
+
(0, assertions_1.assertIsSet)(uuidtable1);
|
|
1119
|
+
const table = await table_1.default.create("JoinUUID");
|
|
1120
|
+
await field_1.default.create({
|
|
1032
1121
|
table: table,
|
|
1033
1122
|
name: "myname",
|
|
1034
1123
|
type: "String",
|
|
1035
1124
|
});
|
|
1036
1125
|
//db.set_sql_logging();
|
|
1037
|
-
await
|
|
1126
|
+
await field_1.default.create({
|
|
1038
1127
|
table: table,
|
|
1039
1128
|
name: "follows",
|
|
1040
1129
|
type: "Key to TableUUID",
|
|
@@ -1052,15 +1141,15 @@ describe("Table with UUID pks", () => {
|
|
|
1052
1141
|
const allRows = await table.getRows();
|
|
1053
1142
|
console.log(allRows);
|
|
1054
1143
|
}
|
|
1055
|
-
expect(rows.length).toBe(1);
|
|
1056
|
-
expect(rows[0].leader).toBe("Jim");
|
|
1057
|
-
expect(rows[0].myname).toBe("Fred");
|
|
1144
|
+
(0, globals_1.expect)(rows.length).toBe(1);
|
|
1145
|
+
(0, globals_1.expect)(rows[0].leader).toBe("Jim");
|
|
1146
|
+
(0, globals_1.expect)(rows[0].myname).toBe("Fred");
|
|
1058
1147
|
await table.delete();
|
|
1059
1148
|
await uuidtable1.delete();
|
|
1060
1149
|
});
|
|
1061
|
-
it("should create and delete table", async () => {
|
|
1150
|
+
(0, globals_1.it)("should create and delete table", async () => {
|
|
1062
1151
|
getState().registerPlugin("mock_plugin", plugin_with_routes);
|
|
1063
|
-
const table = await
|
|
1152
|
+
const table = await table_1.default.create("TableUUID1");
|
|
1064
1153
|
const [pk] = await table.getFields();
|
|
1065
1154
|
await pk.update({ type: "UUID" });
|
|
1066
1155
|
table.fields = null;
|
|
@@ -1070,41 +1159,41 @@ describe("Table with UUID pks", () => {
|
|
|
1070
1159
|
});
|
|
1071
1160
|
}
|
|
1072
1161
|
});
|
|
1073
|
-
describe("external tables", () => {
|
|
1074
|
-
it("should register plugin", async () => {
|
|
1162
|
+
(0, globals_1.describe)("external tables", () => {
|
|
1163
|
+
(0, globals_1.it)("should register plugin", async () => {
|
|
1075
1164
|
getState().registerPlugin("mock_plugin", plugin_with_routes);
|
|
1076
1165
|
});
|
|
1077
|
-
it("should find table", async () => {
|
|
1078
|
-
const table = await
|
|
1079
|
-
expect(!!table).toBe(true);
|
|
1080
|
-
const notable = await
|
|
1081
|
-
expect(!!notable).toBe(false);
|
|
1082
|
-
const tables = await
|
|
1083
|
-
expect(tables.map((t) => t.name)).toContain("exttab");
|
|
1084
|
-
expect(tables.map((t) => t.name)).toContain("books");
|
|
1085
|
-
const etables = await
|
|
1086
|
-
expect(etables.map((t) => t.name)).toEqual(["exttab"]);
|
|
1087
|
-
const dbtables = await
|
|
1088
|
-
expect(dbtables.map((t) => t.name)).not.toContain("exttab");
|
|
1089
|
-
expect(dbtables.map((t) => t.name)).toContain("books");
|
|
1166
|
+
(0, globals_1.it)("should find table", async () => {
|
|
1167
|
+
const table = await table_1.default.findOne({ name: "exttab" });
|
|
1168
|
+
(0, globals_1.expect)(!!table).toBe(true);
|
|
1169
|
+
const notable = await table_1.default.findOne({ name: "exttnosuchab" });
|
|
1170
|
+
(0, globals_1.expect)(!!notable).toBe(false);
|
|
1171
|
+
const tables = await table_1.default.find_with_external();
|
|
1172
|
+
(0, globals_1.expect)(tables.map((t) => t.name)).toContain("exttab");
|
|
1173
|
+
(0, globals_1.expect)(tables.map((t) => t.name)).toContain("books");
|
|
1174
|
+
const etables = await table_1.default.find_with_external({ external: true });
|
|
1175
|
+
(0, globals_1.expect)(etables.map((t) => t.name)).toEqual(["exttab"]);
|
|
1176
|
+
const dbtables = await table_1.default.find_with_external({ external: false });
|
|
1177
|
+
(0, globals_1.expect)(dbtables.map((t) => t.name)).not.toContain("exttab");
|
|
1178
|
+
(0, globals_1.expect)(dbtables.map((t) => t.name)).toContain("books");
|
|
1090
1179
|
});
|
|
1091
1180
|
});
|
|
1092
|
-
describe("distance ordering", () => {
|
|
1093
|
-
it("should create table", async () => {
|
|
1094
|
-
const tc = await
|
|
1095
|
-
await
|
|
1181
|
+
(0, globals_1.describe)("distance ordering", () => {
|
|
1182
|
+
(0, globals_1.it)("should create table", async () => {
|
|
1183
|
+
const tc = await table_1.default.create("geotable1");
|
|
1184
|
+
await field_1.default.create({
|
|
1096
1185
|
table: tc,
|
|
1097
1186
|
label: "Name",
|
|
1098
1187
|
type: "String",
|
|
1099
1188
|
required: true,
|
|
1100
1189
|
});
|
|
1101
|
-
await
|
|
1190
|
+
await field_1.default.create({
|
|
1102
1191
|
table: tc,
|
|
1103
1192
|
label: "Lat",
|
|
1104
1193
|
type: "Float",
|
|
1105
1194
|
required: true,
|
|
1106
1195
|
});
|
|
1107
|
-
await
|
|
1196
|
+
await field_1.default.create({
|
|
1108
1197
|
table: tc,
|
|
1109
1198
|
label: "Long",
|
|
1110
1199
|
type: "Float",
|
|
@@ -1113,22 +1202,23 @@ describe("distance ordering", () => {
|
|
|
1113
1202
|
await tc.insertRow({ name: "Fred", lat: 10, long: 10 });
|
|
1114
1203
|
await tc.insertRow({ name: "George", lat: 20, long: 20 });
|
|
1115
1204
|
});
|
|
1116
|
-
it("should query", async () => {
|
|
1117
|
-
const table = await
|
|
1205
|
+
(0, globals_1.it)("should query", async () => {
|
|
1206
|
+
const table = await table_1.default.findOne({ name: "geotable1" });
|
|
1207
|
+
(0, assertions_1.assertIsSet)(table);
|
|
1118
1208
|
const fred_rows = await table.getRows({}, {
|
|
1119
1209
|
orderBy: {
|
|
1120
1210
|
distance: { lat: 11, long: 11, latField: "lat", longField: "long" },
|
|
1121
1211
|
},
|
|
1122
1212
|
});
|
|
1123
|
-
expect(fred_rows.length).toBe(2);
|
|
1124
|
-
expect(fred_rows[0].name).toBe("Fred");
|
|
1213
|
+
(0, globals_1.expect)(fred_rows.length).toBe(2);
|
|
1214
|
+
(0, globals_1.expect)(fred_rows[0].name).toBe("Fred");
|
|
1125
1215
|
const george_rows = await table.getJoinedRows({
|
|
1126
1216
|
orderBy: {
|
|
1127
1217
|
distance: { lat: 19, long: 19, latField: "lat", longField: "long" },
|
|
1128
1218
|
},
|
|
1129
1219
|
});
|
|
1130
|
-
expect(george_rows.length).toBe(2);
|
|
1131
|
-
expect(george_rows[0].name).toBe("George");
|
|
1220
|
+
(0, globals_1.expect)(george_rows.length).toBe(2);
|
|
1221
|
+
(0, globals_1.expect)(george_rows[0].name).toBe("George");
|
|
1132
1222
|
});
|
|
1133
1223
|
});
|
|
1134
1224
|
//# sourceMappingURL=table.test.js.map
|