@proteinjs/db 1.0.28 → 1.1.0
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/CHANGELOG.md +27 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/Db.d.ts +9 -4
- package/dist/src/Db.d.ts.map +1 -1
- package/dist/src/Db.js.map +1 -1
- package/dist/src/StatementConfigFactory.d.ts +12 -2
- package/dist/src/StatementConfigFactory.d.ts.map +1 -1
- package/dist/src/StatementConfigFactory.js +60 -7
- package/dist/src/StatementConfigFactory.js.map +1 -1
- package/dist/test/ColumnTypesTests.d.ts +1 -1
- package/dist/test/ColumnTypesTests.d.ts.map +1 -1
- package/dist/test/ColumnTypesTests.js +4 -4
- package/dist/test/ColumnTypesTests.js.map +1 -1
- package/dist/test/CrudTests.d.ts +21 -2
- package/dist/test/CrudTests.d.ts.map +1 -1
- package/dist/test/CrudTests.js +299 -37
- package/dist/test/CrudTests.js.map +1 -1
- package/dist/test/TableManagerTests.js +16 -16
- package/dist/test/TableManagerTests.js.map +1 -1
- package/generated/index.ts +1 -1
- package/package.json +3 -3
- package/src/Db.ts +15 -9
- package/src/StatementConfigFactory.ts +58 -3
- package/test/ColumnTypesTests.ts +2 -2
- package/test/CrudTests.ts +205 -26
- package/test/TableManagerTests.ts +13 -13
|
@@ -48,6 +48,6 @@ export declare class TestTable extends Table<TestRecord> {
|
|
|
48
48
|
/**
|
|
49
49
|
* Used for testing purposes only.
|
|
50
50
|
* */
|
|
51
|
-
export declare const
|
|
51
|
+
export declare const getColTypeTestTable: (tableName: string) => TestTable;
|
|
52
52
|
export declare const columnTypeTests: (driver: DbDriver, dropTable: (table: Table<any>) => Promise<void>) => () => void;
|
|
53
53
|
//# sourceMappingURL=ColumnTypesTests.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnTypesTests.d.ts","sourceRoot":"","sources":["../../test/ColumnTypesTests.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IAAI,SAAmB;IACvB,OAAO;;;;;;;;;;;;;;;;;;;;;MAeX;CACJ;AAED;;MAEM;AACN,eAAO,MAAM,mBAAmB,cAAe,MAAM,cAMpD,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,QAAQ,qBAAqB,MAAM,GAAG,CAAC,KAAK,QAAQ,IAAI,CAAC,eAiFhG,CAAC"}
|
|
@@ -51,7 +51,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.columnTypeTests = exports.
|
|
54
|
+
exports.columnTypeTests = exports.getColTypeTestTable = exports.TestTable = void 0;
|
|
55
55
|
var Db_1 = require("../src/Db");
|
|
56
56
|
var Columns_1 = require("../src/Columns");
|
|
57
57
|
var Record_1 = require("../src/Record");
|
|
@@ -85,17 +85,17 @@ exports.TestTable = TestTable;
|
|
|
85
85
|
/**
|
|
86
86
|
* Used for testing purposes only.
|
|
87
87
|
* */
|
|
88
|
-
var
|
|
88
|
+
var getColTypeTestTable = function (tableName) {
|
|
89
89
|
var testTable = new TestTable();
|
|
90
90
|
if (testTable.name === tableName) {
|
|
91
91
|
return new TestTable();
|
|
92
92
|
}
|
|
93
93
|
throw new Error("Cannot find test table: ".concat(tableName));
|
|
94
94
|
};
|
|
95
|
-
exports.
|
|
95
|
+
exports.getColTypeTestTable = getColTypeTestTable;
|
|
96
96
|
var columnTypeTests = function (driver, dropTable) {
|
|
97
97
|
return function () {
|
|
98
|
-
var db = new Db_1.Db(driver, exports.
|
|
98
|
+
var db = new Db_1.Db(driver, exports.getColTypeTestTable);
|
|
99
99
|
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
100
|
return __generator(this, function (_a) {
|
|
101
101
|
switch (_a.label) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnTypesTests.js","sourceRoot":"","sources":["../../test/ColumnTypesTests.ts"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AAC,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;wBAEtE,WAAW;wBACX,qBAAM,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC,EAAA;;wBADpD,WAAW;wBACX,SAAoD,CAAC;;;;aACtD,CAAC,CAAC;QAEH,IAAI,CAAC,yCAAyC,EAAE;;;;;wBACxC,UAAU,GAAmC;4BACjD,aAAa,EAAE,SAAS;4BACxB,YAAY,EAAE,SAAS;4BACvB,WAAW,EAAE,SAAS;4BACtB,aAAa,EAAE,SAAS;4BACxB,aAAa,EAAE,SAAS;4BACxB,UAAU,EAAE,SAAS;4BACrB,cAAc,EAAE,SAAS;4BACzB,YAAY,EAAE,SAAS;4BACvB,UAAU,EAAE,SAAS;4BACrB,cAAc,EAAE,SAAS;4BACzB,YAAY,EAAE,SAAS;4BACvB,WAAW,EAAE,SAAS;4BACtB,oBAAoB,EAAE,SAAS;4BAC/B,eAAe,EAAE,SAAS;yBAC3B,CAAC;wBAEI,SAAS,GAAsB,IAAI,SAAS,EAAE,CAAC;wBAErD,qBAAM,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAA;;wBAAhE,SAAgE,CAAC;;;;aAClE,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAjFW,QAAA,eAAe,mBAiF1B"}
|
package/dist/test/CrudTests.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface Employee extends Record {
|
|
|
9
9
|
startDate?: Date;
|
|
10
10
|
object?: string;
|
|
11
11
|
}
|
|
12
|
-
export declare class
|
|
12
|
+
export declare class EmployeeTestTable extends Table<Employee> {
|
|
13
13
|
name: string;
|
|
14
14
|
columns: {
|
|
15
15
|
id: import("../src/Table").Column<string, any>;
|
|
@@ -24,9 +24,28 @@ export declare class EmployeeTable extends Table<Employee> {
|
|
|
24
24
|
startDate: import("../src/Table").Column<Date | undefined, any>;
|
|
25
25
|
} & {};
|
|
26
26
|
}
|
|
27
|
+
export interface ReservedWordTest extends Record {
|
|
28
|
+
name: string;
|
|
29
|
+
order?: string;
|
|
30
|
+
select?: string;
|
|
31
|
+
join?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare class ReservedWordTestTable extends Table<ReservedWordTest> {
|
|
34
|
+
name: string;
|
|
35
|
+
columns: {
|
|
36
|
+
id: import("../src/Table").Column<string, any>;
|
|
37
|
+
created: import("../src/Table").Column<import("moment").Moment, any>;
|
|
38
|
+
updated: import("../src/Table").Column<import("moment").Moment, any>;
|
|
39
|
+
} & {} & {
|
|
40
|
+
select: import("../src/Table").Column<string | undefined, any>;
|
|
41
|
+
name: import("../src/Table").Column<string, any>;
|
|
42
|
+
order: import("../src/Table").Column<string | undefined, any>;
|
|
43
|
+
join: import("../src/Table").Column<string | undefined, any>;
|
|
44
|
+
} & {};
|
|
45
|
+
}
|
|
27
46
|
/**
|
|
28
47
|
* Used for testing purposes only.
|
|
29
48
|
* */
|
|
30
|
-
export declare const
|
|
49
|
+
export declare const getCrudTestTable: (tableName: string) => EmployeeTestTable | ReservedWordTestTable;
|
|
31
50
|
export declare const crudTests: (driver: DbDriver, dropTable: (table: Table<any>) => Promise<void>) => () => void;
|
|
32
51
|
//# sourceMappingURL=CrudTests.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudTests.d.ts","sourceRoot":"","sources":["../../test/CrudTests.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAM,MAAM,WAAW,CAAC;AACzC,OAAO,EAAqB,MAAM,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,MAAM,WAAW,QAAS,SAAQ,MAAM;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC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dist/test/CrudTests.js
CHANGED
|
@@ -51,15 +51,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.crudTests = exports.
|
|
54
|
+
exports.crudTests = exports.getCrudTestTable = exports.ReservedWordTestTable = exports.EmployeeTestTable = void 0;
|
|
55
55
|
var db_query_1 = require("@proteinjs/db-query");
|
|
56
56
|
var Db_1 = require("../src/Db");
|
|
57
57
|
var Record_1 = require("../src/Record");
|
|
58
58
|
var Columns_1 = require("../src/Columns");
|
|
59
59
|
var Table_1 = require("../src/Table");
|
|
60
|
-
var
|
|
61
|
-
__extends(
|
|
62
|
-
function
|
|
60
|
+
var EmployeeTestTable = /** @class */ (function (_super) {
|
|
61
|
+
__extends(EmployeeTestTable, _super);
|
|
62
|
+
function EmployeeTestTable() {
|
|
63
63
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
64
64
|
_this.name = 'db_test_employee';
|
|
65
65
|
_this.columns = (0, Record_1.withRecordColumns)({
|
|
@@ -72,23 +72,43 @@ var EmployeeTable = /** @class */ (function (_super) {
|
|
|
72
72
|
});
|
|
73
73
|
return _this;
|
|
74
74
|
}
|
|
75
|
-
return
|
|
75
|
+
return EmployeeTestTable;
|
|
76
76
|
}(Table_1.Table));
|
|
77
|
-
exports.
|
|
77
|
+
exports.EmployeeTestTable = EmployeeTestTable;
|
|
78
|
+
var ReservedWordTestTable = /** @class */ (function (_super) {
|
|
79
|
+
__extends(ReservedWordTestTable, _super);
|
|
80
|
+
function ReservedWordTestTable() {
|
|
81
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
82
|
+
_this.name = 'db_test_reserved_word';
|
|
83
|
+
_this.columns = (0, Record_1.withRecordColumns)({
|
|
84
|
+
name: new Columns_1.StringColumn('name'),
|
|
85
|
+
order: new Columns_1.StringColumn('order'),
|
|
86
|
+
select: new Columns_1.StringColumn('select'),
|
|
87
|
+
join: new Columns_1.StringColumn('join'),
|
|
88
|
+
});
|
|
89
|
+
return _this;
|
|
90
|
+
}
|
|
91
|
+
return ReservedWordTestTable;
|
|
92
|
+
}(Table_1.Table));
|
|
93
|
+
exports.ReservedWordTestTable = ReservedWordTestTable;
|
|
78
94
|
/**
|
|
79
95
|
* Used for testing purposes only.
|
|
80
96
|
* */
|
|
81
|
-
var
|
|
82
|
-
var employeeTable = new
|
|
97
|
+
var getCrudTestTable = function (tableName) {
|
|
98
|
+
var employeeTable = new EmployeeTestTable();
|
|
83
99
|
if (employeeTable.name == tableName) {
|
|
84
|
-
return new
|
|
100
|
+
return new EmployeeTestTable();
|
|
101
|
+
}
|
|
102
|
+
var reservedWordTestTable = new ReservedWordTestTable();
|
|
103
|
+
if (reservedWordTestTable.name == tableName) {
|
|
104
|
+
return new ReservedWordTestTable();
|
|
85
105
|
}
|
|
86
106
|
throw new Error("Cannot find test table: ".concat(tableName));
|
|
87
107
|
};
|
|
88
|
-
exports.
|
|
108
|
+
exports.getCrudTestTable = getCrudTestTable;
|
|
89
109
|
var crudTests = function (driver, dropTable) {
|
|
90
110
|
return function () {
|
|
91
|
-
var db = new Db_1.Db(driver, exports.
|
|
111
|
+
var db = new Db_1.Db(driver, exports.getCrudTestTable);
|
|
92
112
|
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
113
|
return __generator(this, function (_a) {
|
|
94
114
|
switch (_a.label) {
|
|
@@ -98,8 +118,11 @@ var crudTests = function (driver, dropTable) {
|
|
|
98
118
|
case 1:
|
|
99
119
|
_a.sent();
|
|
100
120
|
_a.label = 2;
|
|
101
|
-
case 2: return [4 /*yield*/, driver.getTableManager().loadTable(new
|
|
121
|
+
case 2: return [4 /*yield*/, driver.getTableManager().loadTable(new EmployeeTestTable())];
|
|
102
122
|
case 3:
|
|
123
|
+
_a.sent();
|
|
124
|
+
return [4 /*yield*/, driver.getTableManager().loadTable(new ReservedWordTestTable())];
|
|
125
|
+
case 4:
|
|
103
126
|
_a.sent();
|
|
104
127
|
return [2 /*return*/];
|
|
105
128
|
}
|
|
@@ -108,15 +131,18 @@ var crudTests = function (driver, dropTable) {
|
|
|
108
131
|
afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
132
|
return __generator(this, function (_a) {
|
|
110
133
|
switch (_a.label) {
|
|
111
|
-
case 0: return [4 /*yield*/, dropTable(new
|
|
134
|
+
case 0: return [4 /*yield*/, dropTable(new EmployeeTestTable())];
|
|
112
135
|
case 1:
|
|
113
136
|
_a.sent();
|
|
114
|
-
|
|
115
|
-
return [4 /*yield*/, driver.stop()];
|
|
137
|
+
return [4 /*yield*/, dropTable(new ReservedWordTestTable())];
|
|
116
138
|
case 2:
|
|
117
139
|
_a.sent();
|
|
118
|
-
|
|
119
|
-
|
|
140
|
+
if (!driver.stop) return [3 /*break*/, 4];
|
|
141
|
+
return [4 /*yield*/, driver.stop()];
|
|
142
|
+
case 3:
|
|
143
|
+
_a.sent();
|
|
144
|
+
_a.label = 4;
|
|
145
|
+
case 4: return [2 /*return*/];
|
|
120
146
|
}
|
|
121
147
|
});
|
|
122
148
|
}); });
|
|
@@ -126,7 +152,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
126
152
|
switch (_a.label) {
|
|
127
153
|
case 0:
|
|
128
154
|
testEmployee = { name: 'Veronica' };
|
|
129
|
-
emplyeeTable = new
|
|
155
|
+
emplyeeTable = new EmployeeTestTable();
|
|
130
156
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
131
157
|
case 1:
|
|
132
158
|
insertedEmployee = _a.sent();
|
|
@@ -147,7 +173,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
147
173
|
switch (_a.label) {
|
|
148
174
|
case 0:
|
|
149
175
|
testEmployee = { name: 'Veronica' };
|
|
150
|
-
emplyeeTable = new
|
|
176
|
+
emplyeeTable = new EmployeeTestTable();
|
|
151
177
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
152
178
|
case 1:
|
|
153
179
|
insertedEmployee = _a.sent();
|
|
@@ -177,7 +203,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
177
203
|
switch (_a.label) {
|
|
178
204
|
case 0:
|
|
179
205
|
testEmployee = { name: 'Veronica' };
|
|
180
|
-
emplyeeTable = new
|
|
206
|
+
emplyeeTable = new EmployeeTestTable();
|
|
181
207
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
182
208
|
case 1:
|
|
183
209
|
insertedEmployee = _a.sent();
|
|
@@ -205,7 +231,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
205
231
|
testEmployee1 = { name: 'Veronica', department: 'Cake Factory' };
|
|
206
232
|
testEmployee2 = { name: 'Brent', department: 'Cake Factory' };
|
|
207
233
|
testEmployee3 = { name: 'Sean', department: 'Pug Playhouse' };
|
|
208
|
-
emplyeeTable = new
|
|
234
|
+
emplyeeTable = new EmployeeTestTable();
|
|
209
235
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee1)];
|
|
210
236
|
case 1:
|
|
211
237
|
fetchedEmployee1 = _a.sent();
|
|
@@ -241,7 +267,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
241
267
|
testEmployee1 = { name: 'Veronica', department: 'Cake Factory' };
|
|
242
268
|
testEmployee2 = { name: 'Brent', department: 'Cake Factory' };
|
|
243
269
|
testEmployee3 = { name: 'Sean', department: 'Pug Playhouse' };
|
|
244
|
-
emplyeeTable = new
|
|
270
|
+
emplyeeTable = new EmployeeTestTable();
|
|
245
271
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee1)];
|
|
246
272
|
case 1:
|
|
247
273
|
fetchedEmployee1 = _a.sent();
|
|
@@ -278,7 +304,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
278
304
|
jobTitle: null,
|
|
279
305
|
isRemote: false,
|
|
280
306
|
};
|
|
281
|
-
emplyeeTable = new
|
|
307
|
+
emplyeeTable = new EmployeeTestTable();
|
|
282
308
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
283
309
|
case 1:
|
|
284
310
|
insertedEmployee = _a.sent();
|
|
@@ -304,7 +330,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
304
330
|
jobTitle: 'Cowboy',
|
|
305
331
|
isRemote: false,
|
|
306
332
|
};
|
|
307
|
-
emplyeeTable = new
|
|
333
|
+
emplyeeTable = new EmployeeTestTable();
|
|
308
334
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
309
335
|
case 1:
|
|
310
336
|
insertedEmployee = _a.sent();
|
|
@@ -333,7 +359,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
333
359
|
jobTitle: null,
|
|
334
360
|
isRemote: false,
|
|
335
361
|
};
|
|
336
|
-
emplyeeTable = new
|
|
362
|
+
emplyeeTable = new EmployeeTestTable();
|
|
337
363
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
338
364
|
case 1:
|
|
339
365
|
insertedEmployee = _a.sent();
|
|
@@ -362,7 +388,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
362
388
|
testEmployee1 = { name: 'Veronica', jobTitle: 'Engineer' };
|
|
363
389
|
testEmployee2 = { name: 'Zenyatta', jobTitle: null };
|
|
364
390
|
testEmployee3 = { name: 'Cassidy', jobTitle: 'Cowboy' };
|
|
365
|
-
emplyeeTable = new
|
|
391
|
+
emplyeeTable = new EmployeeTestTable();
|
|
366
392
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee1)];
|
|
367
393
|
case 1:
|
|
368
394
|
insertedEmployee1 = _a.sent();
|
|
@@ -404,7 +430,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
404
430
|
});
|
|
405
431
|
}); });
|
|
406
432
|
test('Query with BETWEEN operator', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
407
|
-
var testEmployee1, testEmployee2, testEmployee3,
|
|
433
|
+
var testEmployee1, testEmployee2, testEmployee3, emplyeeTable, insertedEmployee1, insertedEmployee2, insertedEmployee3, betweenQuery, betweenResults, qb;
|
|
408
434
|
return __generator(this, function (_a) {
|
|
409
435
|
switch (_a.label) {
|
|
410
436
|
case 0:
|
|
@@ -423,33 +449,33 @@ var crudTests = function (driver, dropTable) {
|
|
|
423
449
|
jobTitle: 'Cowboy',
|
|
424
450
|
startDate: new Date('2016-05-24T00:00:00Z'),
|
|
425
451
|
};
|
|
426
|
-
|
|
427
|
-
return [4 /*yield*/, db.insert(
|
|
452
|
+
emplyeeTable = new EmployeeTestTable();
|
|
453
|
+
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee1)];
|
|
428
454
|
case 1:
|
|
429
455
|
insertedEmployee1 = _a.sent();
|
|
430
|
-
return [4 /*yield*/, db.insert(
|
|
456
|
+
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee2)];
|
|
431
457
|
case 2:
|
|
432
458
|
insertedEmployee2 = _a.sent();
|
|
433
|
-
return [4 /*yield*/, db.insert(
|
|
459
|
+
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee3)];
|
|
434
460
|
case 3:
|
|
435
461
|
insertedEmployee3 = _a.sent();
|
|
436
|
-
betweenQuery = new db_query_1.QueryBuilder(
|
|
462
|
+
betweenQuery = new db_query_1.QueryBuilder(emplyeeTable.name).condition({
|
|
437
463
|
field: 'startDate',
|
|
438
464
|
operator: 'BETWEEN',
|
|
439
465
|
value: ['2000-06-05T00:00:00Z', '2024-06-05T00:00:00Z'],
|
|
440
466
|
});
|
|
441
|
-
return [4 /*yield*/, db.query(
|
|
467
|
+
return [4 /*yield*/, db.query(emplyeeTable, betweenQuery)];
|
|
442
468
|
case 4:
|
|
443
469
|
betweenResults = _a.sent();
|
|
444
470
|
expect(betweenResults.length).toBe(2);
|
|
445
471
|
expect(betweenResults.some(function (emp) { return emp.name === 'Kiriko'; })).toBe(true);
|
|
446
472
|
expect(betweenResults.some(function (emp) { return emp.name === 'Cassidy'; })).toBe(true);
|
|
447
|
-
qb = new db_query_1.QueryBuilder(
|
|
473
|
+
qb = new db_query_1.QueryBuilder(emplyeeTable.name).condition({
|
|
448
474
|
field: 'id',
|
|
449
475
|
operator: 'IN',
|
|
450
476
|
value: [insertedEmployee1.id, insertedEmployee2.id, insertedEmployee3.id],
|
|
451
477
|
});
|
|
452
|
-
return [4 /*yield*/, db.delete(
|
|
478
|
+
return [4 /*yield*/, db.delete(emplyeeTable, qb)];
|
|
453
479
|
case 5:
|
|
454
480
|
_a.sent();
|
|
455
481
|
return [2 /*return*/];
|
|
@@ -473,7 +499,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
473
499
|
name: 'Cassidy',
|
|
474
500
|
jobTitle: 'Cowboy',
|
|
475
501
|
};
|
|
476
|
-
emplyeeTable = new
|
|
502
|
+
emplyeeTable = new EmployeeTestTable();
|
|
477
503
|
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee1)];
|
|
478
504
|
case 1:
|
|
479
505
|
insertedEmployee1 = _a.sent();
|
|
@@ -513,7 +539,7 @@ var crudTests = function (driver, dropTable) {
|
|
|
513
539
|
case 0:
|
|
514
540
|
testEmployee1 = { name: 'Veronica', jobTitle: 'Software Engineer' };
|
|
515
541
|
testEmployee2 = { name: 'Brent', jobTitle: undefined };
|
|
516
|
-
emplyeeTable = new
|
|
542
|
+
emplyeeTable = new EmployeeTestTable();
|
|
517
543
|
// Insert operation with undefined values
|
|
518
544
|
return [4 /*yield*/, expect(db.insert(emplyeeTable, testEmployee2)).rejects.toThrow()];
|
|
519
545
|
case 1:
|
|
@@ -553,6 +579,242 @@ var crudTests = function (driver, dropTable) {
|
|
|
553
579
|
}
|
|
554
580
|
});
|
|
555
581
|
}); });
|
|
582
|
+
test('Insert with reserved words', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
583
|
+
var testRecord, table, insertedRecord, fetchedRecord;
|
|
584
|
+
return __generator(this, function (_a) {
|
|
585
|
+
switch (_a.label) {
|
|
586
|
+
case 0:
|
|
587
|
+
testRecord = { name: 'Test Name', order: '1', select: 'Option 1' };
|
|
588
|
+
table = new ReservedWordTestTable();
|
|
589
|
+
return [4 /*yield*/, db.insert(table, testRecord)];
|
|
590
|
+
case 1:
|
|
591
|
+
insertedRecord = _a.sent();
|
|
592
|
+
return [4 /*yield*/, db.get(table, { id: insertedRecord.id })];
|
|
593
|
+
case 2:
|
|
594
|
+
fetchedRecord = _a.sent();
|
|
595
|
+
expect(fetchedRecord).toBeTruthy();
|
|
596
|
+
return [4 /*yield*/, db.delete(table, { id: fetchedRecord.id })];
|
|
597
|
+
case 3:
|
|
598
|
+
_a.sent();
|
|
599
|
+
return [2 /*return*/];
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
}); });
|
|
603
|
+
test('Update with reserved words', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
604
|
+
var testRecord, table, insertedRecord, updateCount, fetchedRecord;
|
|
605
|
+
return __generator(this, function (_a) {
|
|
606
|
+
switch (_a.label) {
|
|
607
|
+
case 0:
|
|
608
|
+
testRecord = { name: 'Test Name', order: '1', select: 'Option 1' };
|
|
609
|
+
table = new ReservedWordTestTable();
|
|
610
|
+
return [4 /*yield*/, db.insert(table, testRecord)];
|
|
611
|
+
case 1:
|
|
612
|
+
insertedRecord = _a.sent();
|
|
613
|
+
return [4 /*yield*/, db.update(table, {
|
|
614
|
+
name: 'Updated Name',
|
|
615
|
+
order: '2',
|
|
616
|
+
join: 'Join Option',
|
|
617
|
+
}, { id: insertedRecord.id })];
|
|
618
|
+
case 2:
|
|
619
|
+
updateCount = _a.sent();
|
|
620
|
+
expect(updateCount).toBe(1);
|
|
621
|
+
return [4 /*yield*/, db.get(table, { id: insertedRecord.id })];
|
|
622
|
+
case 3:
|
|
623
|
+
fetchedRecord = _a.sent();
|
|
624
|
+
expect(fetchedRecord.name).toBe('Updated Name');
|
|
625
|
+
expect(fetchedRecord.order).toBe('2');
|
|
626
|
+
expect(fetchedRecord.join).toBe('Join Option');
|
|
627
|
+
return [4 /*yield*/, db.delete(table, { id: fetchedRecord.id })];
|
|
628
|
+
case 4:
|
|
629
|
+
_a.sent();
|
|
630
|
+
return [2 /*return*/];
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
}); });
|
|
634
|
+
test('Delete with reserved words', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
635
|
+
var testRecord, table, insertedRecord, fetchedRecord, deleteCount;
|
|
636
|
+
return __generator(this, function (_a) {
|
|
637
|
+
switch (_a.label) {
|
|
638
|
+
case 0:
|
|
639
|
+
testRecord = { name: 'Test Name', order: '1', select: 'Option 1' };
|
|
640
|
+
table = new ReservedWordTestTable();
|
|
641
|
+
return [4 /*yield*/, db.insert(table, testRecord)];
|
|
642
|
+
case 1:
|
|
643
|
+
insertedRecord = _a.sent();
|
|
644
|
+
return [4 /*yield*/, db.get(table, { id: insertedRecord.id })];
|
|
645
|
+
case 2:
|
|
646
|
+
fetchedRecord = _a.sent();
|
|
647
|
+
expect(fetchedRecord).toBeTruthy();
|
|
648
|
+
return [4 /*yield*/, db.delete(table, { id: fetchedRecord.id })];
|
|
649
|
+
case 3:
|
|
650
|
+
deleteCount = _a.sent();
|
|
651
|
+
expect(deleteCount).toBe(1);
|
|
652
|
+
return [4 /*yield*/, db.get(table, { id: insertedRecord.id })];
|
|
653
|
+
case 4:
|
|
654
|
+
fetchedRecord = _a.sent();
|
|
655
|
+
expect(fetchedRecord).toBeFalsy();
|
|
656
|
+
return [2 /*return*/];
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
}); });
|
|
660
|
+
test('Query with reserved words', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
661
|
+
var testRecord1, testRecord2, testRecord3, table, insertedRecord1, insertedRecord2, insertedRecord3, fetchedRecords, qb;
|
|
662
|
+
return __generator(this, function (_a) {
|
|
663
|
+
switch (_a.label) {
|
|
664
|
+
case 0:
|
|
665
|
+
testRecord1 = { name: 'Test Name 1', order: '1', select: 'Option 1' };
|
|
666
|
+
testRecord2 = { name: 'Test Name 2', order: '1', select: 'Option 1' };
|
|
667
|
+
testRecord3 = { name: 'Test Name 3', order: '2', select: 'Option 2' };
|
|
668
|
+
table = new ReservedWordTestTable();
|
|
669
|
+
return [4 /*yield*/, db.insert(table, testRecord1)];
|
|
670
|
+
case 1:
|
|
671
|
+
insertedRecord1 = _a.sent();
|
|
672
|
+
return [4 /*yield*/, db.insert(table, testRecord2)];
|
|
673
|
+
case 2:
|
|
674
|
+
insertedRecord2 = _a.sent();
|
|
675
|
+
return [4 /*yield*/, db.insert(table, testRecord3)];
|
|
676
|
+
case 3:
|
|
677
|
+
insertedRecord3 = _a.sent();
|
|
678
|
+
return [4 /*yield*/, db.query(table, { order: '1', select: 'Option 1' })];
|
|
679
|
+
case 4:
|
|
680
|
+
fetchedRecords = _a.sent();
|
|
681
|
+
expect(fetchedRecords.length).toBe(2);
|
|
682
|
+
expect(fetchedRecords[0].name).toBe('Test Name 1');
|
|
683
|
+
expect(fetchedRecords[1].name).toBe('Test Name 2');
|
|
684
|
+
qb = new db_query_1.QueryBuilder(table.name).condition({
|
|
685
|
+
field: 'id',
|
|
686
|
+
operator: 'IN',
|
|
687
|
+
value: [insertedRecord1.id, insertedRecord2.id, insertedRecord3.id],
|
|
688
|
+
});
|
|
689
|
+
return [4 /*yield*/, db.delete(table, qb)];
|
|
690
|
+
case 5:
|
|
691
|
+
_a.sent();
|
|
692
|
+
return [2 /*return*/];
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
}); });
|
|
696
|
+
test('Query with sort and reserved words', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
697
|
+
var testRecord1, testRecord2, testRecord3, table, insertedRecord1, insertedRecord2, insertedRecord3, sortQuery, sortResults, qb;
|
|
698
|
+
return __generator(this, function (_a) {
|
|
699
|
+
switch (_a.label) {
|
|
700
|
+
case 0:
|
|
701
|
+
testRecord1 = { name: 'Test Name 1', order: '1', select: 'Option 1' };
|
|
702
|
+
testRecord2 = { name: 'Test Name 2', order: '2', select: 'Option 2' };
|
|
703
|
+
testRecord3 = { name: 'Test Name 3', order: '3', select: 'Option 3' };
|
|
704
|
+
table = new ReservedWordTestTable();
|
|
705
|
+
return [4 /*yield*/, db.insert(table, testRecord1)];
|
|
706
|
+
case 1:
|
|
707
|
+
insertedRecord1 = _a.sent();
|
|
708
|
+
return [4 /*yield*/, db.insert(table, testRecord2)];
|
|
709
|
+
case 2:
|
|
710
|
+
insertedRecord2 = _a.sent();
|
|
711
|
+
return [4 /*yield*/, db.insert(table, testRecord3)];
|
|
712
|
+
case 3:
|
|
713
|
+
insertedRecord3 = _a.sent();
|
|
714
|
+
sortQuery = new db_query_1.QueryBuilder(table.name).sort([
|
|
715
|
+
{ field: 'order', byValues: ['1', '2', '3'] },
|
|
716
|
+
]);
|
|
717
|
+
return [4 /*yield*/, db.query(table, sortQuery)];
|
|
718
|
+
case 4:
|
|
719
|
+
sortResults = _a.sent();
|
|
720
|
+
// Assertions
|
|
721
|
+
expect(sortResults.length).toBe(3);
|
|
722
|
+
expect(sortResults[0].order).toBe('1');
|
|
723
|
+
expect(sortResults[1].order).toBe('2');
|
|
724
|
+
expect(sortResults[2].order).toBe('3');
|
|
725
|
+
qb = new db_query_1.QueryBuilder(table.name).condition({
|
|
726
|
+
field: 'id',
|
|
727
|
+
operator: 'IN',
|
|
728
|
+
value: [insertedRecord1.id, insertedRecord2.id, insertedRecord3.id],
|
|
729
|
+
});
|
|
730
|
+
return [4 /*yield*/, db.delete(table, qb)];
|
|
731
|
+
case 5:
|
|
732
|
+
_a.sent();
|
|
733
|
+
return [2 /*return*/];
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
}); });
|
|
737
|
+
test('Query with reserved words and subquery', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
738
|
+
var testRecord1, testRecord2, table, insertedRecord1, insertedRecord2, subQb, qb, results;
|
|
739
|
+
return __generator(this, function (_a) {
|
|
740
|
+
switch (_a.label) {
|
|
741
|
+
case 0:
|
|
742
|
+
testRecord1 = { name: 'Test Name 1', order: '1', select: 'Option 1' };
|
|
743
|
+
testRecord2 = { name: 'Test Name 2', order: '2', select: 'Option 2' };
|
|
744
|
+
table = new ReservedWordTestTable();
|
|
745
|
+
return [4 /*yield*/, db.insert(table, testRecord1)];
|
|
746
|
+
case 1:
|
|
747
|
+
insertedRecord1 = _a.sent();
|
|
748
|
+
return [4 /*yield*/, db.insert(table, testRecord2)];
|
|
749
|
+
case 2:
|
|
750
|
+
insertedRecord2 = _a.sent();
|
|
751
|
+
subQb = new db_query_1.QueryBuilder(table.name).select({ fields: ['id'] }).condition({
|
|
752
|
+
field: 'select',
|
|
753
|
+
operator: '=',
|
|
754
|
+
value: 'Option 1',
|
|
755
|
+
});
|
|
756
|
+
qb = new db_query_1.QueryBuilder(table.name).condition({
|
|
757
|
+
field: 'id',
|
|
758
|
+
operator: 'IN',
|
|
759
|
+
value: subQb,
|
|
760
|
+
});
|
|
761
|
+
return [4 /*yield*/, db.query(table, qb)];
|
|
762
|
+
case 3:
|
|
763
|
+
results = _a.sent();
|
|
764
|
+
expect(results.length).toBe(1);
|
|
765
|
+
expect(results[0].name).toBe('Test Name 1');
|
|
766
|
+
// Clean up
|
|
767
|
+
return [4 /*yield*/, db.delete(table, { id: insertedRecord1.id })];
|
|
768
|
+
case 4:
|
|
769
|
+
// Clean up
|
|
770
|
+
_a.sent();
|
|
771
|
+
return [4 /*yield*/, db.delete(table, { id: insertedRecord2.id })];
|
|
772
|
+
case 5:
|
|
773
|
+
_a.sent();
|
|
774
|
+
return [2 /*return*/];
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
}); }, 10000);
|
|
778
|
+
test('Case sensitivity', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
779
|
+
var testEmployee, emplyeeTable, insertedEmployee, queryNameInsensitive, nameResultsIns, queryNameSensitive, nameResultsSens;
|
|
780
|
+
return __generator(this, function (_a) {
|
|
781
|
+
switch (_a.label) {
|
|
782
|
+
case 0:
|
|
783
|
+
testEmployee = {
|
|
784
|
+
name: 'Veronica',
|
|
785
|
+
jobTitle: 'Software ENGINEER',
|
|
786
|
+
isRemote: true,
|
|
787
|
+
startDate: new Date('2024-04-01T00:00:00Z'),
|
|
788
|
+
};
|
|
789
|
+
emplyeeTable = new EmployeeTestTable();
|
|
790
|
+
return [4 /*yield*/, db.insert(emplyeeTable, testEmployee)];
|
|
791
|
+
case 1:
|
|
792
|
+
insertedEmployee = _a.sent();
|
|
793
|
+
queryNameInsensitive = new db_query_1.QueryBuilder(emplyeeTable.name).condition({
|
|
794
|
+
field: 'jobTitle',
|
|
795
|
+
operator: '=',
|
|
796
|
+
value: 'SOFTWARE engineer',
|
|
797
|
+
}, undefined, false);
|
|
798
|
+
return [4 /*yield*/, db.query(emplyeeTable, queryNameInsensitive)];
|
|
799
|
+
case 2:
|
|
800
|
+
nameResultsIns = _a.sent();
|
|
801
|
+
expect(nameResultsIns.length).toBe(1);
|
|
802
|
+
queryNameSensitive = new db_query_1.QueryBuilder(emplyeeTable.name).condition({
|
|
803
|
+
field: 'jobTitle',
|
|
804
|
+
operator: '=',
|
|
805
|
+
value: 'SOFTWARE ENGINEER',
|
|
806
|
+
});
|
|
807
|
+
return [4 /*yield*/, db.query(emplyeeTable, queryNameSensitive)];
|
|
808
|
+
case 3:
|
|
809
|
+
nameResultsSens = _a.sent();
|
|
810
|
+
expect(nameResultsSens.length).toBe(0);
|
|
811
|
+
return [4 /*yield*/, db.delete(emplyeeTable, { id: insertedEmployee.id })];
|
|
812
|
+
case 4:
|
|
813
|
+
_a.sent();
|
|
814
|
+
return [2 /*return*/];
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
}); });
|
|
556
818
|
};
|
|
557
819
|
};
|
|
558
820
|
exports.crudTests = crudTests;
|