@naturalcycles/db-lib 9.4.1 → 9.5.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/dist/commondao/common.dao.d.ts +46 -53
- package/dist/commondao/common.dao.js +2 -58
- package/dist/commondao/common.dao.model.d.ts +6 -8
- package/dist/db.model.d.ts +1 -2
- package/dist/db.model.js +0 -1
- package/dist/query/dbQuery.d.ts +12 -14
- package/dist/query/dbQuery.js +0 -6
- package/dist/testing/daoTest.js +0 -1
- package/dist/testing/test.model.d.ts +5 -5
- package/dist/testing/test.model.js +3 -0
- package/package.json +1 -1
- package/src/commondao/common.dao.model.ts +5 -13
- package/src/commondao/common.dao.ts +86 -193
- package/src/db.model.ts +0 -1
- package/src/pipeline/dbPipelineRestore.ts +1 -2
- package/src/query/dbQuery.ts +10 -21
- package/src/testing/daoTest.ts +0 -2
- package/src/testing/test.model.ts +8 -5
package/src/db.model.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
localTime,
|
|
11
11
|
JsonSchemaObject,
|
|
12
12
|
BaseDBEntity,
|
|
13
|
-
Saved,
|
|
14
13
|
} from '@naturalcycles/js-lib'
|
|
15
14
|
import {
|
|
16
15
|
NDJsonStats,
|
|
@@ -217,7 +216,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
|
|
|
217
216
|
}),
|
|
218
217
|
transformLimit({ limit }),
|
|
219
218
|
...(sinceUpdated
|
|
220
|
-
? [transformFilterSync<
|
|
219
|
+
? [transformFilterSync<BaseDBEntity>(r => r.updated >= sinceUpdated)]
|
|
221
220
|
: []),
|
|
222
221
|
transformMap(mapperPerTable[table] || _passthroughMapper, {
|
|
223
222
|
errorMode,
|
package/src/query/dbQuery.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AsyncMapper,
|
|
3
3
|
_truncate,
|
|
4
|
-
Saved,
|
|
5
|
-
AnyObject,
|
|
6
4
|
_objectAssign,
|
|
7
5
|
BaseDBEntity,
|
|
8
6
|
ObjectWithId,
|
|
@@ -239,19 +237,18 @@ export class DBQuery<ROW extends ObjectWithId> {
|
|
|
239
237
|
export class RunnableDBQuery<
|
|
240
238
|
BM extends BaseDBEntity,
|
|
241
239
|
DBM extends BaseDBEntity = BM,
|
|
242
|
-
TM extends AnyObject = BM,
|
|
243
240
|
> extends DBQuery<DBM> {
|
|
244
241
|
/**
|
|
245
242
|
* Pass `table` to override table.
|
|
246
243
|
*/
|
|
247
244
|
constructor(
|
|
248
|
-
public dao: CommonDao<BM, DBM
|
|
245
|
+
public dao: CommonDao<BM, DBM>,
|
|
249
246
|
table?: string,
|
|
250
247
|
) {
|
|
251
248
|
super(table || dao.cfg.table)
|
|
252
249
|
}
|
|
253
250
|
|
|
254
|
-
async runQuery(opt?: CommonDaoOptions): Promise<
|
|
251
|
+
async runQuery(opt?: CommonDaoOptions): Promise<BM[]> {
|
|
255
252
|
return await this.dao.runQuery(this, opt)
|
|
256
253
|
}
|
|
257
254
|
|
|
@@ -259,26 +256,18 @@ export class RunnableDBQuery<
|
|
|
259
256
|
return await this.dao.runQuerySingleColumn<T>(this, opt)
|
|
260
257
|
}
|
|
261
258
|
|
|
262
|
-
async runQueryAsDBM(opt?: CommonDaoOptions): Promise<
|
|
259
|
+
async runQueryAsDBM(opt?: CommonDaoOptions): Promise<DBM[]> {
|
|
263
260
|
return await this.dao.runQueryAsDBM(this, opt)
|
|
264
261
|
}
|
|
265
262
|
|
|
266
|
-
async
|
|
267
|
-
return await this.dao.runQueryAsTM(this, opt)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<BM>>> {
|
|
263
|
+
async runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<BM>> {
|
|
271
264
|
return await this.dao.runQueryExtended(this, opt)
|
|
272
265
|
}
|
|
273
266
|
|
|
274
|
-
async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<
|
|
267
|
+
async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>> {
|
|
275
268
|
return await this.dao.runQueryExtendedAsDBM(this, opt)
|
|
276
269
|
}
|
|
277
270
|
|
|
278
|
-
async runQueryExtendedAsTM(opt?: CommonDaoOptions): Promise<RunQueryResult<TM>> {
|
|
279
|
-
return await this.dao.runQueryExtendedAsTM(this, opt)
|
|
280
|
-
}
|
|
281
|
-
|
|
282
271
|
async runQueryCount(opt?: CommonDaoOptions): Promise<number> {
|
|
283
272
|
return await this.dao.runQueryCount(this, opt)
|
|
284
273
|
}
|
|
@@ -288,24 +277,24 @@ export class RunnableDBQuery<
|
|
|
288
277
|
}
|
|
289
278
|
|
|
290
279
|
async streamQueryForEach(
|
|
291
|
-
mapper: AsyncMapper<
|
|
292
|
-
opt?: CommonDaoStreamForEachOptions<
|
|
280
|
+
mapper: AsyncMapper<BM, void>,
|
|
281
|
+
opt?: CommonDaoStreamForEachOptions<BM>,
|
|
293
282
|
): Promise<void> {
|
|
294
283
|
await this.dao.streamQueryForEach(this, mapper, opt)
|
|
295
284
|
}
|
|
296
285
|
|
|
297
286
|
async streamQueryAsDBMForEach(
|
|
298
|
-
mapper: AsyncMapper<
|
|
287
|
+
mapper: AsyncMapper<DBM, void>,
|
|
299
288
|
opt?: CommonDaoStreamForEachOptions<DBM>,
|
|
300
289
|
): Promise<void> {
|
|
301
290
|
await this.dao.streamQueryAsDBMForEach(this, mapper, opt)
|
|
302
291
|
}
|
|
303
292
|
|
|
304
|
-
streamQuery(opt?: CommonDaoStreamOptions<
|
|
293
|
+
streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM> {
|
|
305
294
|
return this.dao.streamQuery(this, opt)
|
|
306
295
|
}
|
|
307
296
|
|
|
308
|
-
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<
|
|
297
|
+
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM> {
|
|
309
298
|
return this.dao.streamQueryAsDBM(this, opt)
|
|
310
299
|
}
|
|
311
300
|
|
package/src/testing/daoTest.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
createTestItemsBM,
|
|
10
10
|
testItemBMSchema,
|
|
11
11
|
testItemDBMSchema,
|
|
12
|
-
testItemTMSchema,
|
|
13
12
|
TEST_TABLE,
|
|
14
13
|
createTestItemBM,
|
|
15
14
|
testItemDBMJsonSchema,
|
|
@@ -23,7 +22,6 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
|
|
|
23
22
|
db,
|
|
24
23
|
dbmSchema: testItemDBMSchema,
|
|
25
24
|
bmSchema: testItemBMSchema,
|
|
26
|
-
tmSchema: testItemTMSchema,
|
|
27
25
|
logStarted: true,
|
|
28
26
|
logLevel: CommonDaoLogLevel.DATA_FULL,
|
|
29
27
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsonSchema, _range, BaseDBEntity,
|
|
1
|
+
import { jsonSchema, _range, BaseDBEntity, JsonSchemaObject } from '@naturalcycles/js-lib'
|
|
2
2
|
import {
|
|
3
3
|
baseDBEntitySchema,
|
|
4
4
|
binarySchema,
|
|
@@ -50,7 +50,10 @@ export const testItemTMSchema = objectSchema<TestItemTM>({
|
|
|
50
50
|
|
|
51
51
|
export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = jsonSchema
|
|
52
52
|
.rootObject<TestItemBM>({
|
|
53
|
+
// todo: figure out how to not copy-paste these 3 fields
|
|
53
54
|
id: jsonSchema.string(), // todo: not strictly needed here
|
|
55
|
+
created: jsonSchema.unixTimestamp(),
|
|
56
|
+
updated: jsonSchema.unixTimestamp(),
|
|
54
57
|
k1: jsonSchema.string(),
|
|
55
58
|
k2: jsonSchema.oneOf<string | null>([jsonSchema.string(), jsonSchema.null()]).optional(),
|
|
56
59
|
k3: jsonSchema.number().optional(),
|
|
@@ -74,7 +77,7 @@ export const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM> = jsonSchema
|
|
|
74
77
|
})
|
|
75
78
|
.build()
|
|
76
79
|
|
|
77
|
-
export function createTestItemDBM(num = 1):
|
|
80
|
+
export function createTestItemDBM(num = 1): TestItemDBM {
|
|
78
81
|
return {
|
|
79
82
|
id: `id${num}`,
|
|
80
83
|
k1: `v${num}`,
|
|
@@ -86,14 +89,14 @@ export function createTestItemDBM(num = 1): Saved<TestItemDBM> {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
export function createTestItemBM(num = 1):
|
|
92
|
+
export function createTestItemBM(num = 1): TestItemBM {
|
|
90
93
|
return createTestItemDBM(num)
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
export function createTestItemsDBM(count = 1):
|
|
96
|
+
export function createTestItemsDBM(count = 1): TestItemDBM[] {
|
|
94
97
|
return _range(1, count + 1).map(num => createTestItemDBM(num))
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
export function createTestItemsBM(count = 1):
|
|
100
|
+
export function createTestItemsBM(count = 1): TestItemBM[] {
|
|
98
101
|
return _range(1, count + 1).map(num => createTestItemBM(num))
|
|
99
102
|
}
|