@naturalcycles/db-lib 9.27.0 → 9.28.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/adapter/inmemory/queryInMemory.js +4 -1
- package/dist/testing/daoTest.js +8 -0
- package/dist/testing/test.model.d.ts +3 -0
- package/dist/testing/test.model.js +4 -0
- package/package.json +1 -1
- package/src/adapter/inmemory/queryInMemory.ts +5 -2
- package/src/testing/daoTest.ts +13 -0
- package/src/testing/test.model.ts +7 -0
|
@@ -20,7 +20,10 @@ function queryInMemory(q, rows = []) {
|
|
|
20
20
|
// .filter
|
|
21
21
|
// eslint-disable-next-line unicorn/no-array-reduce
|
|
22
22
|
rows = q._filters.reduce((rows, filter) => {
|
|
23
|
-
return rows.filter(row =>
|
|
23
|
+
return rows.filter(row => {
|
|
24
|
+
const value = (0, js_lib_1._get)(row, filter.name);
|
|
25
|
+
return FILTER_FNS[filter.op](value, filter.val);
|
|
26
|
+
});
|
|
24
27
|
}, rows);
|
|
25
28
|
// .select(fieldNames)
|
|
26
29
|
if (q._selectedFieldNames) {
|
package/dist/testing/daoTest.js
CHANGED
|
@@ -151,6 +151,14 @@ function runCommonDaoTest(db, quirks = {}) {
|
|
|
151
151
|
rows = (0, js_lib_1._sortBy)(rows, r => r.id);
|
|
152
152
|
(0, dbTest_1.expectMatch)(expectedItems.filter(i => i.even), rows, quirks);
|
|
153
153
|
});
|
|
154
|
+
test('query nested property', async () => {
|
|
155
|
+
let rows = await dao
|
|
156
|
+
.query()
|
|
157
|
+
.filter('nested.foo', '==', 1)
|
|
158
|
+
.runQuery();
|
|
159
|
+
rows = (0, js_lib_1._sortBy)(rows, r => r.id);
|
|
160
|
+
(0, dbTest_1.expectMatch)(expectedItems.filter(i => i.nested?.foo === 1), rows, quirks);
|
|
161
|
+
});
|
|
154
162
|
}
|
|
155
163
|
if (support.dbQueryOrder) {
|
|
156
164
|
test('query order by k1 desc', async () => {
|
|
@@ -15,6 +15,9 @@ exports.testItemBMSchema = (0, nodejs_lib_1.objectSchema)({
|
|
|
15
15
|
k3: nodejs_lib_1.numberSchema.optional(),
|
|
16
16
|
even: nodejs_lib_1.booleanSchema.optional(),
|
|
17
17
|
b1: nodejs_lib_1.binarySchema.optional(),
|
|
18
|
+
nested: (0, nodejs_lib_1.objectSchema)({
|
|
19
|
+
foo: nodejs_lib_1.numberSchema,
|
|
20
|
+
}).optional(),
|
|
18
21
|
}).concat(nodejs_lib_1.baseDBEntitySchema);
|
|
19
22
|
exports.testItemTMSchema = (0, nodejs_lib_1.objectSchema)({
|
|
20
23
|
k1: nodejs_lib_1.stringSchema,
|
|
@@ -41,6 +44,7 @@ function createTestItemDBM(num = 1) {
|
|
|
41
44
|
k2: `v${num * 2}`,
|
|
42
45
|
k3: num,
|
|
43
46
|
even: num % 2 === 0,
|
|
47
|
+
nested: { foo: num },
|
|
44
48
|
created: MOCK_TS_2018_06_21,
|
|
45
49
|
updated: MOCK_TS_2018_06_21,
|
|
46
50
|
};
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _pick, ObjectWithId } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _get, _pick, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
2
|
import { DBQuery, DBQueryFilterOperator } from '../../query/dbQuery'
|
|
3
3
|
|
|
4
4
|
type FilterFn = (v: any, val: any) => boolean
|
|
@@ -22,7 +22,10 @@ export function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows: R
|
|
|
22
22
|
// .filter
|
|
23
23
|
// eslint-disable-next-line unicorn/no-array-reduce
|
|
24
24
|
rows = q._filters.reduce((rows, filter) => {
|
|
25
|
-
return rows.filter(row =>
|
|
25
|
+
return rows.filter(row => {
|
|
26
|
+
const value = _get(row, filter.name as string)
|
|
27
|
+
return FILTER_FNS[filter.op](value, filter.val)
|
|
28
|
+
})
|
|
26
29
|
}, rows)
|
|
27
30
|
|
|
28
31
|
// .select(fieldNames)
|
package/src/testing/daoTest.ts
CHANGED
|
@@ -196,6 +196,19 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
|
|
|
196
196
|
quirks,
|
|
197
197
|
)
|
|
198
198
|
})
|
|
199
|
+
|
|
200
|
+
test('query nested property', async () => {
|
|
201
|
+
let rows = await dao
|
|
202
|
+
.query()
|
|
203
|
+
.filter('nested.foo' as any, '==', 1)
|
|
204
|
+
.runQuery()
|
|
205
|
+
rows = _sortBy(rows, r => r.id)
|
|
206
|
+
expectMatch(
|
|
207
|
+
expectedItems.filter(i => i.nested?.foo === 1),
|
|
208
|
+
rows,
|
|
209
|
+
quirks,
|
|
210
|
+
)
|
|
211
|
+
})
|
|
199
212
|
}
|
|
200
213
|
|
|
201
214
|
if (support.dbQueryOrder) {
|
|
@@ -24,6 +24,9 @@ export interface TestItemBM extends BaseDBEntity {
|
|
|
24
24
|
k3?: number
|
|
25
25
|
even?: boolean
|
|
26
26
|
b1?: Buffer
|
|
27
|
+
nested?: {
|
|
28
|
+
foo: number
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
export interface TestItemDBM extends TestItemBM {}
|
|
@@ -39,6 +42,9 @@ export const testItemBMSchema = objectSchema<TestItemBM>({
|
|
|
39
42
|
k3: numberSchema.optional(),
|
|
40
43
|
even: booleanSchema.optional(),
|
|
41
44
|
b1: binarySchema.optional(),
|
|
45
|
+
nested: objectSchema({
|
|
46
|
+
foo: numberSchema,
|
|
47
|
+
}).optional(),
|
|
42
48
|
}).concat(baseDBEntitySchema as any)
|
|
43
49
|
|
|
44
50
|
export const testItemTMSchema = objectSchema<TestItemTM>({
|
|
@@ -68,6 +74,7 @@ export function createTestItemDBM(num = 1): TestItemDBM {
|
|
|
68
74
|
k2: `v${num * 2}`,
|
|
69
75
|
k3: num,
|
|
70
76
|
even: num % 2 === 0,
|
|
77
|
+
nested: { foo: num },
|
|
71
78
|
created: MOCK_TS_2018_06_21,
|
|
72
79
|
updated: MOCK_TS_2018_06_21,
|
|
73
80
|
}
|