@naturalcycles/db-lib 8.40.1 → 8.41.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/adapter/file/file.db.d.ts +1 -1
- package/dist/commondao/common.dao.d.ts +8 -8
- package/dist/commondao/common.dao.js +11 -6
- package/dist/testing/daoTest.js +4 -4
- package/dist/testing/dbTest.js +4 -4
- package/dist/testing/test.model.d.ts +2 -2
- package/dist/testing/test.model.js +6 -3
- package/package.json +4 -5
- package/src/adapter/file/file.db.ts +2 -2
- package/src/commondao/common.dao.ts +21 -19
- package/src/query/dbQuery.ts +2 -2
- package/src/testing/daoTest.ts +4 -4
- package/src/testing/dbTest.ts +4 -4
- package/src/testing/test.model.ts +14 -11
|
@@ -36,7 +36,7 @@ export declare class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
36
36
|
loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
|
|
37
37
|
saveFile<ROW extends ObjectWithId>(table: string, _rows: ROW[]): Promise<void>;
|
|
38
38
|
saveFiles<ROW extends ObjectWithId>(ops: DBSaveBatchOperation<ROW>[]): Promise<void>;
|
|
39
|
-
sortRows
|
|
39
|
+
private sortRows;
|
|
40
40
|
private logStarted;
|
|
41
41
|
private logFinished;
|
|
42
42
|
}
|
|
@@ -14,14 +14,14 @@ export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends
|
|
|
14
14
|
cfg: CommonDaoCfg<BM, DBM, TM, ID>;
|
|
15
15
|
constructor(cfg: CommonDaoCfg<BM, DBM, TM, ID>);
|
|
16
16
|
create(part?: Partial<BM>, opt?: CommonDaoOptions): Saved<BM>;
|
|
17
|
-
getById(id: undefined, opt?: CommonDaoOptions): Promise<null>;
|
|
18
|
-
getById(id?: ID, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
|
|
17
|
+
getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
18
|
+
getById(id?: ID | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
|
|
19
19
|
getByIdOrEmpty(id: ID, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<BM>>;
|
|
20
20
|
getByIdAsDBMOrEmpty(id: ID, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<DBM>;
|
|
21
|
-
getByIdAsDBM(id: undefined, opt?: CommonDaoOptions): Promise<null>;
|
|
22
|
-
getByIdAsDBM(id?: ID, opt?: CommonDaoOptions): Promise<DBM | null>;
|
|
23
|
-
getByIdAsTM(id: undefined, opt?: CommonDaoOptions): Promise<null>;
|
|
24
|
-
getByIdAsTM(id?: ID, opt?: CommonDaoOptions): Promise<TM | null>;
|
|
21
|
+
getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
22
|
+
getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>;
|
|
23
|
+
getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
24
|
+
getByIdAsTM(id?: ID | null, opt?: CommonDaoOptions): Promise<TM | null>;
|
|
25
25
|
getByIds(ids: ID[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
26
26
|
getByIdsAsDBM(ids: ID[], opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
27
27
|
requireById(id: ID, opt?: CommonDaoOptions): Promise<Saved<BM>>;
|
|
@@ -103,8 +103,8 @@ export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends
|
|
|
103
103
|
/**
|
|
104
104
|
* @returns number of deleted items
|
|
105
105
|
*/
|
|
106
|
-
deleteById(id: undefined, opt?: CommonDaoOptions): Promise<0>;
|
|
107
|
-
deleteById(id?: ID, opt?: CommonDaoOptions): Promise<number>;
|
|
106
|
+
deleteById(id: undefined | null, opt?: CommonDaoOptions): Promise<0>;
|
|
107
|
+
deleteById(id?: ID | null, opt?: CommonDaoOptions): Promise<number>;
|
|
108
108
|
deleteByIds(ids: ID[], opt?: CommonDaoOptions): Promise<number>;
|
|
109
109
|
/**
|
|
110
110
|
* Pass `stream: true` option to use Streaming: it will Stream the query, batch by 500, and execute
|
|
@@ -56,9 +56,10 @@ class CommonDao {
|
|
|
56
56
|
}
|
|
57
57
|
// CREATE
|
|
58
58
|
create(part = {}, opt = {}) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const bm = this.cfg.hooks.beforeCreate(part);
|
|
60
|
+
// First assignIdCreatedUpdated, then validate!
|
|
61
|
+
this.assignIdCreatedUpdated(bm, opt);
|
|
62
|
+
return this.validateAndConvert(bm, this.cfg.bmSchema, db_model_1.DBModelType.BM, opt);
|
|
62
63
|
}
|
|
63
64
|
async getById(id, opt = {}) {
|
|
64
65
|
if (!id)
|
|
@@ -220,7 +221,7 @@ class CommonDao {
|
|
|
220
221
|
(0, js_lib_1._assert)(q._selectedFieldNames?.length === 1, `runQuerySingleColumn requires exactly 1 column to be selected: ${q.pretty()}`);
|
|
221
222
|
const col = q._selectedFieldNames[0];
|
|
222
223
|
const { rows } = await this.runQueryExtended(q, opt);
|
|
223
|
-
return rows.map(r => r[col]);
|
|
224
|
+
return rows.map((r) => r[col]);
|
|
224
225
|
}
|
|
225
226
|
/**
|
|
226
227
|
* Convenience method that runs multiple queries in parallel and then merges their results together.
|
|
@@ -435,13 +436,17 @@ class CommonDao {
|
|
|
435
436
|
}
|
|
436
437
|
}
|
|
437
438
|
assignIdCreatedUpdated(obj, opt = {}) {
|
|
439
|
+
var _a;
|
|
438
440
|
const now = Math.floor(Date.now() / 1000);
|
|
439
441
|
obj.id || (obj.id = this.cfg.hooks.createId?.(obj));
|
|
440
442
|
if (this.cfg.created) {
|
|
441
|
-
|
|
443
|
+
;
|
|
444
|
+
(_a = obj)['created'] || (_a['created'] = obj['updated'] || now);
|
|
442
445
|
}
|
|
443
446
|
if (this.cfg.updated) {
|
|
444
|
-
|
|
447
|
+
;
|
|
448
|
+
obj['updated'] =
|
|
449
|
+
opt.preserveUpdatedCreated && obj['updated'] ? obj['updated'] : now;
|
|
445
450
|
}
|
|
446
451
|
return obj;
|
|
447
452
|
}
|
package/dist/testing/daoTest.js
CHANGED
|
@@ -41,7 +41,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
|
|
|
41
41
|
// CREATE TABLE, DROP
|
|
42
42
|
if (createTable) {
|
|
43
43
|
test('createTable, dropIfExists=true', async () => {
|
|
44
|
-
await dao.createTable(test_model_1.testItemDBMJsonSchema
|
|
44
|
+
await dao.createTable(test_model_1.testItemDBMJsonSchema, { dropIfExists: true });
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
if (querying) {
|
|
@@ -55,7 +55,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
|
|
|
55
55
|
if (eventualConsistencyDelay)
|
|
56
56
|
await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
|
|
57
57
|
expect(await dao.query().runQuery()).toEqual([]);
|
|
58
|
-
expect(await dao.query().runQueryCount()).
|
|
58
|
+
expect(await dao.query().runQueryCount()).toBe(0);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
// GET empty
|
|
@@ -81,7 +81,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
|
|
|
81
81
|
await dao.save(item3);
|
|
82
82
|
const item3Loaded = await dao.requireById(item3.id);
|
|
83
83
|
(0, dbTest_1.expectMatch)([item3], [item3Loaded], quirks);
|
|
84
|
-
expect(item3Loaded.k2).
|
|
84
|
+
expect(item3Loaded.k2).toBeNull();
|
|
85
85
|
expect(Object.keys(item3)).toContain('k2');
|
|
86
86
|
expect(item3.k2).toBeNull();
|
|
87
87
|
});
|
|
@@ -98,7 +98,7 @@ function runCommonDaoTest(db, features = {}, quirks = {}) {
|
|
|
98
98
|
expected.updated = item3.updated; // as it's mutated
|
|
99
99
|
const item3Loaded = await dao.requireById(item3.id);
|
|
100
100
|
(0, dbTest_1.expectMatch)([expected], [item3Loaded], quirks);
|
|
101
|
-
expect(item3Loaded.k2).
|
|
101
|
+
expect(item3Loaded.k2).toBeUndefined();
|
|
102
102
|
expect(Object.keys(item3Loaded)).not.toContain('k2');
|
|
103
103
|
expect(Object.keys(item3)).toContain('k2');
|
|
104
104
|
expect(item3.k2).toBeUndefined();
|
package/dist/testing/dbTest.js
CHANGED
|
@@ -28,7 +28,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
|
|
|
28
28
|
// CREATE TABLE, DROP
|
|
29
29
|
if (createTable) {
|
|
30
30
|
test('createTable, dropIfExists=true', async () => {
|
|
31
|
-
await db.createTable(test_model_1.TEST_TABLE, test_model_1.testItemDBMJsonSchema
|
|
31
|
+
await db.createTable(test_model_1.TEST_TABLE, test_model_1.testItemDBMJsonSchema, { dropIfExists: true });
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
if (querying) {
|
|
@@ -42,7 +42,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
|
|
|
42
42
|
if (eventualConsistencyDelay)
|
|
43
43
|
await (0, js_lib_1.pDelay)(eventualConsistencyDelay);
|
|
44
44
|
expect((await db.runQuery(queryAll())).rows).toEqual([]);
|
|
45
|
-
expect(await db.runQueryCount(queryAll())).
|
|
45
|
+
expect(await db.runQueryCount(queryAll())).toBe(0);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
// GET empty
|
|
@@ -68,7 +68,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
|
|
|
68
68
|
await db.saveBatch(test_model_1.TEST_TABLE, [item3]);
|
|
69
69
|
const item3Loaded = (await db.getByIds(test_model_1.TEST_TABLE, [item3.id]))[0];
|
|
70
70
|
expectMatch([item3], [item3Loaded], quirks);
|
|
71
|
-
expect(item3Loaded.k2).
|
|
71
|
+
expect(item3Loaded.k2).toBeNull();
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
if (documentDB) {
|
|
@@ -83,7 +83,7 @@ function runCommonDBTest(db, features = {}, quirks = {}) {
|
|
|
83
83
|
await db.saveBatch(test_model_1.TEST_TABLE, [item3]);
|
|
84
84
|
const item3Loaded = (await db.getByIds(test_model_1.TEST_TABLE, [item3.id]))[0];
|
|
85
85
|
expectMatch([expected], [item3Loaded], quirks);
|
|
86
|
-
expect(item3Loaded.k2).
|
|
86
|
+
expect(item3Loaded.k2).toBeUndefined();
|
|
87
87
|
expect(Object.keys(item3Loaded)).not.toContain('k2');
|
|
88
88
|
});
|
|
89
89
|
}
|
|
@@ -17,8 +17,8 @@ export interface TestItemTM {
|
|
|
17
17
|
export declare const testItemBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemBM, TestItemBM>;
|
|
18
18
|
export declare const testItemDBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemDBM, TestItemDBM>;
|
|
19
19
|
export declare const testItemTMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemTM, TestItemTM>;
|
|
20
|
-
export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib
|
|
21
|
-
export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib
|
|
20
|
+
export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib").JsonSchemaObject<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity<string>>>;
|
|
21
|
+
export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib").JsonSchemaObject<TestItemDBM>;
|
|
22
22
|
export declare function createTestItemDBM(num?: number): TestItemDBM;
|
|
23
23
|
export declare function createTestItemBM(num?: number): Saved<TestItemBM>;
|
|
24
24
|
export declare function createTestItemsDBM(count?: number): TestItemDBM[];
|
|
@@ -31,8 +31,10 @@ exports.testItemBMJsonSchema = js_lib_1.jsonSchema
|
|
|
31
31
|
even: js_lib_1.jsonSchema.boolean().optional(),
|
|
32
32
|
b1: js_lib_1.jsonSchema.buffer().optional(),
|
|
33
33
|
})
|
|
34
|
-
.baseDBEntity()
|
|
35
|
-
|
|
34
|
+
.baseDBEntity()
|
|
35
|
+
.build();
|
|
36
|
+
exports.testItemDBMJsonSchema = js_lib_1.jsonSchema
|
|
37
|
+
.rootObject({
|
|
36
38
|
// todo: figure out how to not copy-paste these 3 fields
|
|
37
39
|
id: js_lib_1.jsonSchema.string(),
|
|
38
40
|
created: js_lib_1.jsonSchema.unixTimestamp(),
|
|
@@ -42,7 +44,8 @@ exports.testItemDBMJsonSchema = js_lib_1.jsonSchema.rootObject({
|
|
|
42
44
|
k3: js_lib_1.jsonSchema.number().optional(),
|
|
43
45
|
even: js_lib_1.jsonSchema.boolean().optional(),
|
|
44
46
|
b1: js_lib_1.jsonSchema.buffer().optional(),
|
|
45
|
-
})
|
|
47
|
+
})
|
|
48
|
+
.build();
|
|
46
49
|
function createTestItemDBM(num = 1) {
|
|
47
50
|
return {
|
|
48
51
|
id: `id${num}`,
|
package/package.json
CHANGED
|
@@ -10,10 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@naturalcycles/bench-lib": "^1.0.0",
|
|
13
|
-
"@naturalcycles/dev-lib": "^
|
|
14
|
-
"@types/node": "^
|
|
15
|
-
"jest": "^
|
|
16
|
-
"weak-napi": "^2.0.2"
|
|
13
|
+
"@naturalcycles/dev-lib": "^13.0.0",
|
|
14
|
+
"@types/node": "^18.0.3",
|
|
15
|
+
"jest": "^29.0.0"
|
|
17
16
|
},
|
|
18
17
|
"files": [
|
|
19
18
|
"dist",
|
|
@@ -42,7 +41,7 @@
|
|
|
42
41
|
"engines": {
|
|
43
42
|
"node": ">=14.15"
|
|
44
43
|
},
|
|
45
|
-
"version": "8.
|
|
44
|
+
"version": "8.41.1",
|
|
46
45
|
"description": "Lowest Common Denominator API to supported Databases",
|
|
47
46
|
"keywords": [
|
|
48
47
|
"db",
|
|
@@ -256,11 +256,11 @@ export class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
256
256
|
this.logFinished(started, op)
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
sortRows<ROW>(rows: ROW[]): ROW[] {
|
|
259
|
+
private sortRows<ROW extends ObjectWithId>(rows: ROW[]): ROW[] {
|
|
260
260
|
rows = rows.map(r => _filterUndefinedValues(r))
|
|
261
261
|
|
|
262
262
|
if (this.cfg.sortOnSave) {
|
|
263
|
-
_sortBy(rows, r => r[this.cfg.sortOnSave!.name], true)
|
|
263
|
+
_sortBy(rows, r => r[this.cfg.sortOnSave!.name as keyof ROW], true)
|
|
264
264
|
if (this.cfg.sortOnSave.descending) rows.reverse() // mutates
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -84,7 +84,7 @@ export class CommonDao<
|
|
|
84
84
|
beforeDBMValidate: dbm => dbm,
|
|
85
85
|
beforeDBMToBM: dbm => dbm as any,
|
|
86
86
|
beforeBMToDBM: bm => bm as any,
|
|
87
|
-
beforeTMToBM: tm => tm,
|
|
87
|
+
beforeTMToBM: tm => tm as any,
|
|
88
88
|
beforeBMToTM: bm => bm as any,
|
|
89
89
|
anonymize: dbm => dbm,
|
|
90
90
|
onValidationError: err => err,
|
|
@@ -106,15 +106,16 @@ export class CommonDao<
|
|
|
106
106
|
|
|
107
107
|
// CREATE
|
|
108
108
|
create(part: Partial<BM> = {}, opt: CommonDaoOptions = {}): Saved<BM> {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
const bm = this.cfg.hooks!.beforeCreate!(part)
|
|
110
|
+
// First assignIdCreatedUpdated, then validate!
|
|
111
|
+
this.assignIdCreatedUpdated(bm as any, opt)
|
|
112
|
+
return this.validateAndConvert(bm, this.cfg.bmSchema, DBModelType.BM, opt)
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
// GET
|
|
115
|
-
async getById(id: undefined, opt?: CommonDaoOptions): Promise<null>
|
|
116
|
-
async getById(id?: ID, opt?: CommonDaoOptions): Promise<Saved<BM> | null>
|
|
117
|
-
async getById(id?: ID, opt: CommonDaoOptions = {}): Promise<Saved<BM> | null> {
|
|
116
|
+
async getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
117
|
+
async getById(id?: ID | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>
|
|
118
|
+
async getById(id?: ID | null, opt: CommonDaoOptions = {}): Promise<Saved<BM> | null> {
|
|
118
119
|
if (!id) return null
|
|
119
120
|
const op = `getById(${id})`
|
|
120
121
|
const table = opt.table || this.cfg.table
|
|
@@ -154,9 +155,9 @@ export class CommonDao<
|
|
|
154
155
|
return await this.bmToDBM(bm, opt)
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
async getByIdAsDBM(id: undefined, opt?: CommonDaoOptions): Promise<null>
|
|
158
|
-
async getByIdAsDBM(id?: ID, opt?: CommonDaoOptions): Promise<DBM | null>
|
|
159
|
-
async getByIdAsDBM(id?: ID, opt: CommonDaoOptions = {}): Promise<DBM | null> {
|
|
158
|
+
async getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
159
|
+
async getByIdAsDBM(id?: ID | null, opt?: CommonDaoOptions): Promise<DBM | null>
|
|
160
|
+
async getByIdAsDBM(id?: ID | null, opt: CommonDaoOptions = {}): Promise<DBM | null> {
|
|
160
161
|
if (!id) return null
|
|
161
162
|
const op = `getByIdAsDBM(${id})`
|
|
162
163
|
const table = opt.table || this.cfg.table
|
|
@@ -169,9 +170,9 @@ export class CommonDao<
|
|
|
169
170
|
return dbm || null
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
async getByIdAsTM(id: undefined, opt?: CommonDaoOptions): Promise<null>
|
|
173
|
-
async getByIdAsTM(id?: ID, opt?: CommonDaoOptions): Promise<TM | null>
|
|
174
|
-
async getByIdAsTM(id?: ID, opt: CommonDaoOptions = {}): Promise<TM | null> {
|
|
173
|
+
async getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>
|
|
174
|
+
async getByIdAsTM(id?: ID | null, opt?: CommonDaoOptions): Promise<TM | null>
|
|
175
|
+
async getByIdAsTM(id?: ID | null, opt: CommonDaoOptions = {}): Promise<TM | null> {
|
|
175
176
|
if (!id) return null
|
|
176
177
|
const op = `getByIdAsTM(${id})`
|
|
177
178
|
const table = opt.table || this.cfg.table
|
|
@@ -302,7 +303,7 @@ export class CommonDao<
|
|
|
302
303
|
const col = q._selectedFieldNames[0]!
|
|
303
304
|
|
|
304
305
|
const { rows } = await this.runQueryExtended(q, opt)
|
|
305
|
-
return rows.map(r => r[col
|
|
306
|
+
return rows.map((r: any) => r[col])
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
/**
|
|
@@ -594,11 +595,12 @@ export class CommonDao<
|
|
|
594
595
|
obj.id ||= this.cfg.hooks!.createId?.(obj as BM)
|
|
595
596
|
|
|
596
597
|
if (this.cfg.created) {
|
|
597
|
-
obj['created'] ||= obj['updated'] || now
|
|
598
|
+
;(obj as any)['created'] ||= (obj as any)['updated'] || now
|
|
598
599
|
}
|
|
599
600
|
|
|
600
601
|
if (this.cfg.updated) {
|
|
601
|
-
obj
|
|
602
|
+
;(obj as any)['updated'] =
|
|
603
|
+
opt.preserveUpdatedCreated && (obj as any)['updated'] ? (obj as any)['updated'] : now
|
|
602
604
|
}
|
|
603
605
|
|
|
604
606
|
return obj as any
|
|
@@ -779,9 +781,9 @@ export class CommonDao<
|
|
|
779
781
|
/**
|
|
780
782
|
* @returns number of deleted items
|
|
781
783
|
*/
|
|
782
|
-
async deleteById(id: undefined, opt?: CommonDaoOptions): Promise<0>
|
|
783
|
-
async deleteById(id?: ID, opt?: CommonDaoOptions): Promise<number>
|
|
784
|
-
async deleteById(id?: ID, opt: CommonDaoOptions = {}): Promise<number> {
|
|
784
|
+
async deleteById(id: undefined | null, opt?: CommonDaoOptions): Promise<0>
|
|
785
|
+
async deleteById(id?: ID | null, opt?: CommonDaoOptions): Promise<number>
|
|
786
|
+
async deleteById(id?: ID | null, opt: CommonDaoOptions = {}): Promise<number> {
|
|
785
787
|
if (!id) return 0
|
|
786
788
|
this.requireWriteAccess()
|
|
787
789
|
this.requireObjectMutability(opt)
|
package/src/query/dbQuery.ts
CHANGED
|
@@ -186,8 +186,8 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
tokens.push(
|
|
189
|
-
...this._filters.map(f => `${f.name}${f.op}${f.val}`),
|
|
190
|
-
...this._orders.map(o => `order by ${o.name}${o.descending ? ' desc' : ''}`),
|
|
189
|
+
...this._filters.map(f => `${f.name as string}${f.op}${f.val}`),
|
|
190
|
+
...this._orders.map(o => `order by ${o.name as string}${o.descending ? ' desc' : ''}`),
|
|
191
191
|
)
|
|
192
192
|
|
|
193
193
|
if (this._groupByFieldNames) {
|
package/src/testing/daoTest.ts
CHANGED
|
@@ -66,7 +66,7 @@ export function runCommonDaoTest(
|
|
|
66
66
|
// CREATE TABLE, DROP
|
|
67
67
|
if (createTable) {
|
|
68
68
|
test('createTable, dropIfExists=true', async () => {
|
|
69
|
-
await dao.createTable(testItemDBMJsonSchema
|
|
69
|
+
await dao.createTable(testItemDBMJsonSchema, { dropIfExists: true })
|
|
70
70
|
})
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -84,7 +84,7 @@ export function runCommonDaoTest(
|
|
|
84
84
|
test('runQuery(all), runQueryCount should return empty', async () => {
|
|
85
85
|
if (eventualConsistencyDelay) await pDelay(eventualConsistencyDelay)
|
|
86
86
|
expect(await dao.query().runQuery()).toEqual([])
|
|
87
|
-
expect(await dao.query().runQueryCount()).
|
|
87
|
+
expect(await dao.query().runQueryCount()).toBe(0)
|
|
88
88
|
})
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -114,7 +114,7 @@ export function runCommonDaoTest(
|
|
|
114
114
|
await dao.save(item3)
|
|
115
115
|
const item3Loaded = await dao.requireById(item3.id)
|
|
116
116
|
expectMatch([item3], [item3Loaded], quirks)
|
|
117
|
-
expect(item3Loaded.k2).
|
|
117
|
+
expect(item3Loaded.k2).toBeNull()
|
|
118
118
|
expect(Object.keys(item3)).toContain('k2')
|
|
119
119
|
expect(item3.k2).toBeNull()
|
|
120
120
|
})
|
|
@@ -135,7 +135,7 @@ export function runCommonDaoTest(
|
|
|
135
135
|
|
|
136
136
|
const item3Loaded = await dao.requireById(item3.id)
|
|
137
137
|
expectMatch([expected], [item3Loaded], quirks)
|
|
138
|
-
expect(item3Loaded.k2).
|
|
138
|
+
expect(item3Loaded.k2).toBeUndefined()
|
|
139
139
|
expect(Object.keys(item3Loaded)).not.toContain('k2')
|
|
140
140
|
expect(Object.keys(item3)).toContain('k2')
|
|
141
141
|
expect(item3.k2).toBeUndefined()
|
package/src/testing/dbTest.ts
CHANGED
|
@@ -110,7 +110,7 @@ export function runCommonDBTest(
|
|
|
110
110
|
// CREATE TABLE, DROP
|
|
111
111
|
if (createTable) {
|
|
112
112
|
test('createTable, dropIfExists=true', async () => {
|
|
113
|
-
await db.createTable(TEST_TABLE, testItemDBMJsonSchema
|
|
113
|
+
await db.createTable(TEST_TABLE, testItemDBMJsonSchema, { dropIfExists: true })
|
|
114
114
|
})
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -128,7 +128,7 @@ export function runCommonDBTest(
|
|
|
128
128
|
test('runQuery(all), runQueryCount should return empty', async () => {
|
|
129
129
|
if (eventualConsistencyDelay) await pDelay(eventualConsistencyDelay)
|
|
130
130
|
expect((await db.runQuery(queryAll())).rows).toEqual([])
|
|
131
|
-
expect(await db.runQueryCount(queryAll())).
|
|
131
|
+
expect(await db.runQueryCount(queryAll())).toBe(0)
|
|
132
132
|
})
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -158,7 +158,7 @@ export function runCommonDBTest(
|
|
|
158
158
|
await db.saveBatch(TEST_TABLE, [item3])
|
|
159
159
|
const item3Loaded = (await db.getByIds<TestItemDBM>(TEST_TABLE, [item3.id]))[0]!
|
|
160
160
|
expectMatch([item3], [item3Loaded], quirks)
|
|
161
|
-
expect(item3Loaded.k2).
|
|
161
|
+
expect(item3Loaded.k2).toBeNull()
|
|
162
162
|
})
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -175,7 +175,7 @@ export function runCommonDBTest(
|
|
|
175
175
|
await db.saveBatch(TEST_TABLE, [item3])
|
|
176
176
|
const item3Loaded = (await db.getByIds<TestItemDBM>(TEST_TABLE, [item3.id]))[0]!
|
|
177
177
|
expectMatch([expected], [item3Loaded], quirks)
|
|
178
|
-
expect(item3Loaded.k2).
|
|
178
|
+
expect(item3Loaded.k2).toBeUndefined()
|
|
179
179
|
expect(Object.keys(item3Loaded)).not.toContain('k2')
|
|
180
180
|
})
|
|
181
181
|
}
|
|
@@ -58,18 +58,21 @@ export const testItemBMJsonSchema = jsonSchema
|
|
|
58
58
|
b1: jsonSchema.buffer().optional(),
|
|
59
59
|
})
|
|
60
60
|
.baseDBEntity()
|
|
61
|
+
.build()
|
|
61
62
|
|
|
62
|
-
export const testItemDBMJsonSchema = jsonSchema
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
export const testItemDBMJsonSchema = jsonSchema
|
|
64
|
+
.rootObject<TestItemDBM>({
|
|
65
|
+
// todo: figure out how to not copy-paste these 3 fields
|
|
66
|
+
id: jsonSchema.string(),
|
|
67
|
+
created: jsonSchema.unixTimestamp(),
|
|
68
|
+
updated: jsonSchema.unixTimestamp(),
|
|
69
|
+
k1: jsonSchema.string(),
|
|
70
|
+
k2: jsonSchema.string().optional(),
|
|
71
|
+
k3: jsonSchema.number().optional(),
|
|
72
|
+
even: jsonSchema.boolean().optional(),
|
|
73
|
+
b1: jsonSchema.buffer().optional(),
|
|
74
|
+
})
|
|
75
|
+
.build()
|
|
73
76
|
|
|
74
77
|
export function createTestItemDBM(num = 1): TestItemDBM {
|
|
75
78
|
return {
|