forked from pubkey/rxdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrx-query-mingo.ts
79 lines (75 loc) · 1.61 KB
/
rx-query-mingo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { useOperators, OperatorType } from 'mingo/core';
import { Query } from 'mingo/query';
import type { MangoQuerySelector } from './types/index.d.ts';
import {
$project,
$sort
} from 'mingo/operators/pipeline';
import {
$and,
$not,
$or,
$nor
} from 'mingo/operators/query/logical';
import {
$eq,
$ne,
$gt,
$gte,
$lt,
$lte,
$nin,
$in
} from 'mingo/operators/query/comparison';
import {
$regex,
$mod
} from 'mingo/operators/query/evaluation';
import {
$elemMatch,
$size
} from 'mingo/operators/query/array';
import {
$exists,
$type
} from 'mingo/operators/query/element';
let mingoInitDone = false;
/**
* The MongoDB query library is huge and we do not need all the operators.
* If you add an operator here, make sure that you properly add a test in
* the file /test/unit/rx-storage-query-correctness.test.ts
*
* @link https://github.com/kofrasa/mingo#es6
*/
export function getMingoQuery<RxDocType>(
selector?: MangoQuerySelector<RxDocType>
) {
if (!mingoInitDone) {
useOperators(OperatorType.PIPELINE, {
$sort,
$project
} as any);
useOperators(OperatorType.QUERY, {
$and,
$eq,
$elemMatch,
$exists,
$gt,
$gte,
$in,
$lt,
$lte,
$ne,
$nin,
$mod,
$nor,
$not,
$or,
$regex,
$size,
$type,
} as any);
mingoInitDone = true;
}
return new Query(selector as any);
}