@kidus.dev/flowdb 1.0.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/README.md +15 -0
- package/dist/core/blob/blob.d.ts +25 -0
- package/dist/core/blob/blob.d.ts.map +1 -0
- package/dist/core/blob/blob.js +57 -0
- package/dist/core/blob/blob_disk_driver.d.ts +27 -0
- package/dist/core/blob/blob_disk_driver.d.ts.map +1 -0
- package/dist/core/blob/blob_disk_driver.js +179 -0
- package/dist/core/blob/blob_storage.d.ts +90 -0
- package/dist/core/blob/blob_storage.d.ts.map +1 -0
- package/dist/core/blob/blob_storage.js +248 -0
- package/dist/core/collection/collection.d.ts +99 -0
- package/dist/core/collection/collection.d.ts.map +1 -0
- package/dist/core/collection/collection.js +226 -0
- package/dist/core/collection/document.d.ts +24 -0
- package/dist/core/collection/document.d.ts.map +1 -0
- package/dist/core/collection/document.js +86 -0
- package/dist/core/collection/driver/collection_file_driver.d.ts +20 -0
- package/dist/core/collection/driver/collection_file_driver.d.ts.map +1 -0
- package/dist/core/collection/driver/collection_file_driver.js +90 -0
- package/dist/core/collection/driver/collection_operations.d.ts +43 -0
- package/dist/core/collection/driver/collection_operations.d.ts.map +1 -0
- package/dist/core/collection/driver/collection_operations.js +278 -0
- package/dist/core/collection/query/compares.d.ts +90 -0
- package/dist/core/collection/query/compares.d.ts.map +1 -0
- package/dist/core/collection/query/compares.js +362 -0
- package/dist/core/collection/query/filtering.d.ts +14 -0
- package/dist/core/collection/query/filtering.d.ts.map +1 -0
- package/dist/core/collection/query/filtering.js +176 -0
- package/dist/core/collection/query/query_builder.d.ts +145 -0
- package/dist/core/collection/query/query_builder.d.ts.map +1 -0
- package/dist/core/collection/query/query_builder.js +196 -0
- package/dist/core/collection/query/query_executor.d.ts +87 -0
- package/dist/core/collection/query/query_executor.d.ts.map +1 -0
- package/dist/core/collection/query/query_executor.js +348 -0
- package/dist/core/collection/query/relation.d.ts +29 -0
- package/dist/core/collection/query/relation.d.ts.map +1 -0
- package/dist/core/collection/query/relation.js +40 -0
- package/dist/core/database/backup.d.ts +26 -0
- package/dist/core/database/backup.d.ts.map +1 -0
- package/dist/core/database/backup.js +114 -0
- package/dist/core/database/database.d.ts +57 -0
- package/dist/core/database/database.d.ts.map +1 -0
- package/dist/core/database/database.js +179 -0
- package/dist/core/database/database_file_driver.d.ts +27 -0
- package/dist/core/database/database_file_driver.d.ts.map +1 -0
- package/dist/core/database/database_file_driver.js +135 -0
- package/dist/core/store/store.d.ts +24 -0
- package/dist/core/store/store.d.ts.map +1 -0
- package/dist/core/store/store.js +54 -0
- package/dist/core/store/store_file_driver.d.ts +26 -0
- package/dist/core/store/store_file_driver.d.ts.map +1 -0
- package/dist/core/store/store_file_driver.js +87 -0
- package/dist/tools/encryptor.d.ts +17 -0
- package/dist/tools/encryptor.d.ts.map +1 -0
- package/dist/tools/encryptor.js +80 -0
- package/dist/tools/format.d.ts +10 -0
- package/dist/tools/format.d.ts.map +1 -0
- package/dist/tools/format.js +40 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/json.d.ts +19 -0
- package/dist/tools/json.d.ts.map +1 -0
- package/dist/tools/json.js +232 -0
- package/dist/tools/performance.d.ts +20 -0
- package/dist/tools/performance.d.ts.map +1 -0
- package/dist/tools/performance.js +53 -0
- package/dist/tools/print_colored.d.ts +47 -0
- package/dist/tools/print_colored.d.ts.map +1 -0
- package/dist/tools/print_colored.js +119 -0
- package/dist/tools/random.d.ts +46 -0
- package/dist/tools/random.d.ts.map +1 -0
- package/dist/tools/random.js +214 -0
- package/package.json +40 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query_builder.d.ts","sourceRoot":"","sources":["../../../../src/core/collection/query/query_builder.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,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Q,GAAG,SAAS,CAAC;IAGjC,UAAU,CAAC,EACT,MAAM,EACN,MAAM,GACP,EAAE;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC7B,GAAG,QAAQ,GAAG,SAAS;IAKlB,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAG3E,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,QAAQ,GAAG,SAAS;CAGjE"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import Collection from "../collection";
|
|
2
|
+
import Document from "../document";
|
|
3
|
+
import CollectionOperations from "../driver/collection_operations";
|
|
4
|
+
import QueryExecutor from "./query_executor";
|
|
5
|
+
export default class QueryBuilder {
|
|
6
|
+
_executor;
|
|
7
|
+
constructor({ debug, safe, collection, collectionOperations, }) {
|
|
8
|
+
this._executor = new QueryExecutor({
|
|
9
|
+
collection,
|
|
10
|
+
collectionOperations,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
get executor() {
|
|
14
|
+
return this._executor;
|
|
15
|
+
}
|
|
16
|
+
where(field, opts = {}) {
|
|
17
|
+
const compare = {
|
|
18
|
+
field,
|
|
19
|
+
type: "and",
|
|
20
|
+
...opts,
|
|
21
|
+
};
|
|
22
|
+
this._executor.addCondition(compare);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
and(field, opts = {}) {
|
|
26
|
+
const compare = {
|
|
27
|
+
field,
|
|
28
|
+
type: "and",
|
|
29
|
+
...opts,
|
|
30
|
+
};
|
|
31
|
+
this._executor.addCondition(compare);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
or(field, opts = {}) {
|
|
35
|
+
const compare = {
|
|
36
|
+
field,
|
|
37
|
+
type: "or",
|
|
38
|
+
...opts,
|
|
39
|
+
};
|
|
40
|
+
this._executor.addCondition(compare);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
pick(field) {
|
|
44
|
+
this._executor.addPick(field);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
pickMany(fields) {
|
|
48
|
+
for (const field of fields) {
|
|
49
|
+
this._executor.addPick(field);
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
omit(field) {
|
|
54
|
+
this._executor.addOmit(field);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
omitMany(fields) {
|
|
58
|
+
for (const field of fields) {
|
|
59
|
+
this._executor.addOmit(field);
|
|
60
|
+
}
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
skip(skip) {
|
|
64
|
+
this._executor.skip = skip;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
limit(limit) {
|
|
68
|
+
this._executor.take = limit;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
take(take) {
|
|
72
|
+
this._executor.take = take;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
skipAndTake({ skip, take } = {}) {
|
|
76
|
+
this._executor.skip = skip;
|
|
77
|
+
this._executor.take = take;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
orderBy(field, { desc = false } = {}) {
|
|
81
|
+
const order = desc ? "desc" : "asc";
|
|
82
|
+
this._executor.addOrder(field, order);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
include(name) {
|
|
86
|
+
this._executor.addInclude(name);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
includeMany(names) {
|
|
90
|
+
for (const name of names) {
|
|
91
|
+
this._executor.addInclude(name);
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
// READ
|
|
96
|
+
async get() {
|
|
97
|
+
return await this._executor.get();
|
|
98
|
+
}
|
|
99
|
+
getSync() {
|
|
100
|
+
return this._executor.getSync();
|
|
101
|
+
}
|
|
102
|
+
async getRandom() {
|
|
103
|
+
return await this._executor.getRandom();
|
|
104
|
+
}
|
|
105
|
+
getRandomSync() {
|
|
106
|
+
return this._executor.getRandomSync();
|
|
107
|
+
}
|
|
108
|
+
async getShuffled() {
|
|
109
|
+
return await this._executor.getShuffled();
|
|
110
|
+
}
|
|
111
|
+
getShuffledSync() {
|
|
112
|
+
return this._executor.getShuffledSync();
|
|
113
|
+
}
|
|
114
|
+
async getRandomMany(count = 1) {
|
|
115
|
+
return await this._executor.getRandomMany(count);
|
|
116
|
+
}
|
|
117
|
+
getRandomManySync(count = 1) {
|
|
118
|
+
return this._executor.getRandomManySync(count);
|
|
119
|
+
}
|
|
120
|
+
async getFirst() {
|
|
121
|
+
return await this._executor.getFirst();
|
|
122
|
+
}
|
|
123
|
+
getFirstSync() {
|
|
124
|
+
return this._executor.getFirstSync();
|
|
125
|
+
}
|
|
126
|
+
async getLast() {
|
|
127
|
+
return await this._executor.getLast();
|
|
128
|
+
}
|
|
129
|
+
getLastSync() {
|
|
130
|
+
return this._executor.getLastSync();
|
|
131
|
+
}
|
|
132
|
+
async getAt(index) {
|
|
133
|
+
return await this._executor.getAt(index);
|
|
134
|
+
}
|
|
135
|
+
getAtSync(index) {
|
|
136
|
+
return this._executor.getAtSync(index);
|
|
137
|
+
}
|
|
138
|
+
async count() {
|
|
139
|
+
return await this._executor.count();
|
|
140
|
+
}
|
|
141
|
+
countSync() {
|
|
142
|
+
return this._executor.countSync();
|
|
143
|
+
}
|
|
144
|
+
// UPDATE
|
|
145
|
+
async update(data) {
|
|
146
|
+
return await this._executor.update(data);
|
|
147
|
+
}
|
|
148
|
+
updateSync(data) {
|
|
149
|
+
return this._executor.updateSync(data);
|
|
150
|
+
}
|
|
151
|
+
async updateFrom(update) {
|
|
152
|
+
return await this._executor.updateFrom(update);
|
|
153
|
+
}
|
|
154
|
+
updateFromSync(update) {
|
|
155
|
+
return this._executor.updateFromSync(update);
|
|
156
|
+
}
|
|
157
|
+
async updateMany(data, { count } = {}) {
|
|
158
|
+
return await this._executor.updateMany(data, { count });
|
|
159
|
+
}
|
|
160
|
+
updateManySync(data, { count } = {}) {
|
|
161
|
+
return this._executor.updateManySync(data, { count });
|
|
162
|
+
}
|
|
163
|
+
async updateManyFrom(update, { count } = {}) {
|
|
164
|
+
return await this._executor.updateManyFrom(update, { count });
|
|
165
|
+
}
|
|
166
|
+
updateManyFromSync(update, { count } = {}) {
|
|
167
|
+
return this._executor.updateManyFromSync(update, { count });
|
|
168
|
+
}
|
|
169
|
+
// DELETE
|
|
170
|
+
async delete() {
|
|
171
|
+
return await this._executor.delete();
|
|
172
|
+
}
|
|
173
|
+
deleteSync() {
|
|
174
|
+
return this._executor.deleteSync();
|
|
175
|
+
}
|
|
176
|
+
async deleteMany() {
|
|
177
|
+
return await this._executor.deleteMany();
|
|
178
|
+
}
|
|
179
|
+
deleteManySync() {
|
|
180
|
+
return this._executor.deleteManySync();
|
|
181
|
+
}
|
|
182
|
+
// UPSERT
|
|
183
|
+
async upsert({ update, insert, }) {
|
|
184
|
+
return await this._executor.upsert({ update, insert });
|
|
185
|
+
}
|
|
186
|
+
upsertSync({ update, insert, }) {
|
|
187
|
+
return this._executor.upsertSync({ update, insert });
|
|
188
|
+
}
|
|
189
|
+
// ADD IF ABSENT
|
|
190
|
+
async addIfAbsent(data) {
|
|
191
|
+
return await this._executor.addIfAbsent(data);
|
|
192
|
+
}
|
|
193
|
+
addIfAbsentSync(data) {
|
|
194
|
+
return this._executor.addIfAbsentSync(data);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Collection from "../collection";
|
|
2
|
+
import Document from "../document";
|
|
3
|
+
import CollectionOperations from "../driver/collection_operations";
|
|
4
|
+
import type { SortOrder } from "./compares";
|
|
5
|
+
type Condition = Record<string, any>;
|
|
6
|
+
export default class QueryExecutor {
|
|
7
|
+
private _collection;
|
|
8
|
+
private _collectionOperations;
|
|
9
|
+
private _conditions;
|
|
10
|
+
private _pick;
|
|
11
|
+
private _omit;
|
|
12
|
+
private _orderBys;
|
|
13
|
+
private _includes;
|
|
14
|
+
private _skip?;
|
|
15
|
+
private _take?;
|
|
16
|
+
constructor({ collection, collectionOperations, }: {
|
|
17
|
+
collection: Collection;
|
|
18
|
+
collectionOperations: CollectionOperations;
|
|
19
|
+
});
|
|
20
|
+
addCondition(condition: Condition): void;
|
|
21
|
+
addPick(pick: string): void;
|
|
22
|
+
addOmit(omit: string): void;
|
|
23
|
+
addPickMany(pickMany: string[]): void;
|
|
24
|
+
addOmitMany(omitMany: string[]): void;
|
|
25
|
+
addOrder(field: string, order: SortOrder): void;
|
|
26
|
+
addInclude(name: string, opts?: {
|
|
27
|
+
limit?: number;
|
|
28
|
+
orderBy?: [string, boolean];
|
|
29
|
+
}): void;
|
|
30
|
+
set skip(skip: number | undefined);
|
|
31
|
+
set take(take: number | undefined);
|
|
32
|
+
get(): Promise<Document[]>;
|
|
33
|
+
getSync(): Document[];
|
|
34
|
+
getRandom(): Promise<Document | undefined>;
|
|
35
|
+
getRandomSync(): Document | undefined;
|
|
36
|
+
getRandomMany(count: number): Promise<Document[]>;
|
|
37
|
+
getRandomManySync(count: number): Document[];
|
|
38
|
+
getShuffled(): Promise<Document[]>;
|
|
39
|
+
getShuffledSync(): Document[];
|
|
40
|
+
getFirst(): Promise<Document | undefined>;
|
|
41
|
+
getFirstSync(): Document | undefined;
|
|
42
|
+
getLast(): Promise<Document | undefined>;
|
|
43
|
+
getLastSync(): Document | undefined;
|
|
44
|
+
getAt(index: number): Promise<Document | undefined>;
|
|
45
|
+
getAtSync(index: number): Document | undefined;
|
|
46
|
+
count(): Promise<number>;
|
|
47
|
+
countSync(): number;
|
|
48
|
+
add(data: Record<string, any>): Promise<Document>;
|
|
49
|
+
addSync(data: Record<string, any>): Document;
|
|
50
|
+
addMany(data: Record<string, any>[]): Promise<Document[]>;
|
|
51
|
+
addManySync(data: Record<string, any>[]): Document[];
|
|
52
|
+
update(data: Record<string, any>): Promise<Document | undefined>;
|
|
53
|
+
updateSync(data: Record<string, any>): Document | undefined;
|
|
54
|
+
updateFrom(update: (data: Record<string, any>) => Record<string, any>): Promise<Document | undefined>;
|
|
55
|
+
updateFromSync(update: (data: Record<string, any>) => Record<string, any>): Document | undefined;
|
|
56
|
+
updateMany(data: Record<string, any>, opts?: {
|
|
57
|
+
count?: number;
|
|
58
|
+
}): Promise<Document[]>;
|
|
59
|
+
updateManySync(data: Record<string, any>, opts?: {
|
|
60
|
+
count?: number;
|
|
61
|
+
}): Document[];
|
|
62
|
+
updateManyFrom(update: (data: Record<string, any>) => Record<string, any>, opts?: {
|
|
63
|
+
count?: number;
|
|
64
|
+
}): Promise<Document[]>;
|
|
65
|
+
updateManyFromSync(update: (data: Record<string, any>) => Record<string, any>, opts?: {
|
|
66
|
+
count?: number;
|
|
67
|
+
}): Document[];
|
|
68
|
+
delete(): Promise<Document | undefined>;
|
|
69
|
+
deleteSync(): Document | undefined;
|
|
70
|
+
deleteMany(): Promise<Document[]>;
|
|
71
|
+
deleteManySync(): Document[];
|
|
72
|
+
upsert({ update, insert, }: {
|
|
73
|
+
update: Record<string, any>;
|
|
74
|
+
insert: Record<string, any>;
|
|
75
|
+
}): Promise<Document | undefined>;
|
|
76
|
+
upsertSync({ update, insert, }: {
|
|
77
|
+
update: Record<string, any>;
|
|
78
|
+
insert: Record<string, any>;
|
|
79
|
+
}): Document | undefined;
|
|
80
|
+
addIfAbsent(data: Record<string, any>): Promise<Document>;
|
|
81
|
+
addIfAbsentSync(data: Record<string, any>): Document;
|
|
82
|
+
toCSV(): string;
|
|
83
|
+
private _getRecords;
|
|
84
|
+
toString(): string;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=query_executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5B,QAAQ,EAAE;IAwBP,MAAM,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAc7C,UAAU,IAAI,QAAQ,GAAG,SAAS;IAY5B,UAAU,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAavC,cAAc,IAAI,QAAQ,EAAE;IAetB,MAAM,CAAC,EACX,MAAM,EACN,MAAM,GACP,EAAE;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC7B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAmBjC,UAAU,CAAC,EACT,MAAM,EACN,MAAM,GACP,EAAE;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC7B,GAAG,QAAQ,GAAG,SAAS;IAiBlB,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;IAO/D,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,QAAQ;IAQpD,KAAK,IAAI,MAAM;IAKf,OAAO,CAAC,WAAW;IAuBnB,QAAQ,IAAI,MAAM;CAOnB"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { Json, Random } from "../../../tools";
|
|
2
|
+
import Relation from "./relation";
|
|
3
|
+
import Collection from "../collection";
|
|
4
|
+
import Document from "../document";
|
|
5
|
+
import CollectionOperations from "../driver/collection_operations";
|
|
6
|
+
import { Filtering } from "./filtering";
|
|
7
|
+
export default class QueryExecutor {
|
|
8
|
+
_collection;
|
|
9
|
+
_collectionOperations;
|
|
10
|
+
_conditions = [];
|
|
11
|
+
_pick = new Set();
|
|
12
|
+
_omit = new Set();
|
|
13
|
+
_orderBys = {};
|
|
14
|
+
_includes = {};
|
|
15
|
+
_skip;
|
|
16
|
+
_take;
|
|
17
|
+
constructor({ collection, collectionOperations, }) {
|
|
18
|
+
this._collection = collection;
|
|
19
|
+
this._collectionOperations = collectionOperations;
|
|
20
|
+
}
|
|
21
|
+
// Setters for all class properties
|
|
22
|
+
addCondition(condition) {
|
|
23
|
+
this._conditions.push(condition);
|
|
24
|
+
}
|
|
25
|
+
addPick(pick) {
|
|
26
|
+
this._pick.add(pick);
|
|
27
|
+
}
|
|
28
|
+
addOmit(omit) {
|
|
29
|
+
this._omit.add(omit);
|
|
30
|
+
}
|
|
31
|
+
addPickMany(pickMany) {
|
|
32
|
+
pickMany.forEach((p) => this._pick.add(p));
|
|
33
|
+
}
|
|
34
|
+
addOmitMany(omitMany) {
|
|
35
|
+
omitMany.forEach((o) => this._omit.add(o));
|
|
36
|
+
}
|
|
37
|
+
addOrder(field, order) {
|
|
38
|
+
this._orderBys[field] = order;
|
|
39
|
+
}
|
|
40
|
+
addInclude(name, opts = {}) {
|
|
41
|
+
const relation = this._collection.relations[name];
|
|
42
|
+
if (!relation)
|
|
43
|
+
return;
|
|
44
|
+
this._includes[name] = relation;
|
|
45
|
+
}
|
|
46
|
+
set skip(skip) {
|
|
47
|
+
this._skip = skip;
|
|
48
|
+
}
|
|
49
|
+
set take(take) {
|
|
50
|
+
this._take = take;
|
|
51
|
+
}
|
|
52
|
+
// --- READ
|
|
53
|
+
async get() {
|
|
54
|
+
let records = await this._collectionOperations.getAll();
|
|
55
|
+
records = this._getRecords(records);
|
|
56
|
+
records = await Filtering.includedDocuments(records, this._includes);
|
|
57
|
+
return records;
|
|
58
|
+
}
|
|
59
|
+
getSync() {
|
|
60
|
+
let records = this._collectionOperations.getAllSync();
|
|
61
|
+
records = this._getRecords(records);
|
|
62
|
+
records = Filtering.includedDocumentsSync(records, this._includes);
|
|
63
|
+
return records;
|
|
64
|
+
}
|
|
65
|
+
async getRandom() {
|
|
66
|
+
let records = await this._collectionOperations.getAll();
|
|
67
|
+
records = this._getRecords(records);
|
|
68
|
+
records = await Filtering.includedDocuments(records, this._includes);
|
|
69
|
+
return Random.pickOne(records);
|
|
70
|
+
}
|
|
71
|
+
getRandomSync() {
|
|
72
|
+
let records = this._collectionOperations.getAllSync();
|
|
73
|
+
records = this._getRecords(records);
|
|
74
|
+
records = Filtering.includedDocumentsSync(records, this._includes);
|
|
75
|
+
return Random.pickOne(records);
|
|
76
|
+
}
|
|
77
|
+
async getRandomMany(count) {
|
|
78
|
+
let records = await this._collectionOperations.getAll();
|
|
79
|
+
records = this._getRecords(records);
|
|
80
|
+
records = await Filtering.includedDocuments(records, this._includes);
|
|
81
|
+
return Random.pickMany(records, { count });
|
|
82
|
+
}
|
|
83
|
+
getRandomManySync(count) {
|
|
84
|
+
let records = this._collectionOperations.getAllSync();
|
|
85
|
+
records = this._getRecords(records);
|
|
86
|
+
records = Filtering.includedDocumentsSync(records, this._includes);
|
|
87
|
+
return Random.pickMany(records, { count });
|
|
88
|
+
}
|
|
89
|
+
async getShuffled() {
|
|
90
|
+
let records = await this._collectionOperations.getAll();
|
|
91
|
+
records = this._getRecords(records);
|
|
92
|
+
records = await Filtering.includedDocuments(records, this._includes);
|
|
93
|
+
return Random.shuffle(records);
|
|
94
|
+
}
|
|
95
|
+
getShuffledSync() {
|
|
96
|
+
let records = this._collectionOperations.getAllSync();
|
|
97
|
+
records = this._getRecords(records);
|
|
98
|
+
records = Filtering.includedDocumentsSync(records, this._includes);
|
|
99
|
+
return Random.shuffle(records);
|
|
100
|
+
}
|
|
101
|
+
async getFirst() {
|
|
102
|
+
const list = await this.get();
|
|
103
|
+
return list[0];
|
|
104
|
+
}
|
|
105
|
+
getFirstSync() {
|
|
106
|
+
const list = this.getSync();
|
|
107
|
+
return list[0];
|
|
108
|
+
}
|
|
109
|
+
async getLast() {
|
|
110
|
+
const list = await this.get();
|
|
111
|
+
return list.length > 0 ? list[list.length - 1] : undefined;
|
|
112
|
+
}
|
|
113
|
+
getLastSync() {
|
|
114
|
+
const list = this.getSync();
|
|
115
|
+
return list.length > 0 ? list[list.length - 1] : undefined;
|
|
116
|
+
}
|
|
117
|
+
async getAt(index) {
|
|
118
|
+
const list = await this.get();
|
|
119
|
+
return list[index];
|
|
120
|
+
}
|
|
121
|
+
getAtSync(index) {
|
|
122
|
+
const list = this.getSync();
|
|
123
|
+
return list[index];
|
|
124
|
+
}
|
|
125
|
+
async count() {
|
|
126
|
+
const list = await this.get();
|
|
127
|
+
return list.length;
|
|
128
|
+
}
|
|
129
|
+
countSync() {
|
|
130
|
+
return this.getSync().length;
|
|
131
|
+
}
|
|
132
|
+
// --- CREATE
|
|
133
|
+
async add(data) {
|
|
134
|
+
return await this._collectionOperations.add(data);
|
|
135
|
+
}
|
|
136
|
+
addSync(data) {
|
|
137
|
+
return this._collectionOperations.addSync(data);
|
|
138
|
+
}
|
|
139
|
+
async addMany(data) {
|
|
140
|
+
return await this._collectionOperations.addMany(data);
|
|
141
|
+
}
|
|
142
|
+
addManySync(data) {
|
|
143
|
+
return this._collectionOperations.addManySync(data);
|
|
144
|
+
}
|
|
145
|
+
// --- UPDATE
|
|
146
|
+
async update(data) {
|
|
147
|
+
const records = await this._collectionOperations.getAll();
|
|
148
|
+
let matchedRecords = Filtering.matchedDocuments(records, this._conditions);
|
|
149
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
150
|
+
matchedRecords = Filtering.sortedDocuments(Array.from(matchedRecords), this._orderBys);
|
|
151
|
+
}
|
|
152
|
+
const single = Array.from(matchedRecords)[0];
|
|
153
|
+
if (single) {
|
|
154
|
+
return ((await this._collectionOperations.updateOneRecordById(single.id, data)) ?? undefined);
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
updateSync(data) {
|
|
159
|
+
const records = this._collectionOperations.getAllSync();
|
|
160
|
+
let matchedRecords = Filtering.matchedDocuments(records, this._conditions);
|
|
161
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
162
|
+
matchedRecords = Filtering.sortedDocuments(Array.from(matchedRecords), this._orderBys);
|
|
163
|
+
}
|
|
164
|
+
const single = Array.from(matchedRecords)[0];
|
|
165
|
+
if (single) {
|
|
166
|
+
return (this._collectionOperations.updateOneRecordByIdSync(single.id, {
|
|
167
|
+
...single.data,
|
|
168
|
+
...data,
|
|
169
|
+
}) ?? undefined);
|
|
170
|
+
}
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
async updateFrom(update) {
|
|
174
|
+
const records = await this._collectionOperations.getAll();
|
|
175
|
+
let matchedRecords = Filtering.matchedDocuments(records, this._conditions);
|
|
176
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
177
|
+
matchedRecords = Filtering.sortedDocuments(Array.from(matchedRecords), this._orderBys);
|
|
178
|
+
}
|
|
179
|
+
const single = Array.from(matchedRecords)[0];
|
|
180
|
+
if (single) {
|
|
181
|
+
return ((await this._collectionOperations.updateOneRecordById(single.id, update(single.data))) ?? undefined);
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
updateFromSync(update) {
|
|
186
|
+
const records = this._collectionOperations.getAllSync();
|
|
187
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
188
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
189
|
+
results = Filtering.sortedDocuments(Array.from(results), this._orderBys);
|
|
190
|
+
}
|
|
191
|
+
const single = Array.from(results)[0];
|
|
192
|
+
if (single) {
|
|
193
|
+
return (this._collectionOperations.updateOneRecordByIdSync(single.id, update(single.data)) ?? undefined);
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
async updateMany(data, opts = {}) {
|
|
198
|
+
const records = await this._collectionOperations.getAll();
|
|
199
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
200
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
201
|
+
results = Filtering.sortedDocuments(Array.from(results).slice(), this._orderBys);
|
|
202
|
+
}
|
|
203
|
+
if (opts.count !== undefined) {
|
|
204
|
+
results = Array.from(results).slice(0, opts.count);
|
|
205
|
+
}
|
|
206
|
+
const ids = Array.from(results).map((doc) => doc.id);
|
|
207
|
+
return await this._collectionOperations.updateManyRecordsByIdsWithSameValue(ids, data);
|
|
208
|
+
}
|
|
209
|
+
updateManySync(data, opts = {}) {
|
|
210
|
+
const records = this._collectionOperations.getAllSync();
|
|
211
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
212
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
213
|
+
results = Filtering.sortedDocuments(Array.from(results).slice(), this._orderBys);
|
|
214
|
+
}
|
|
215
|
+
if (opts.count !== undefined) {
|
|
216
|
+
results = Array.from(results).slice(0, opts.count);
|
|
217
|
+
}
|
|
218
|
+
const ids = Array.from(results).map((doc) => doc.id);
|
|
219
|
+
return this._collectionOperations.updateManyRecordsByIdsWithSameValueSync(ids, data);
|
|
220
|
+
}
|
|
221
|
+
async updateManyFrom(update, opts = {}) {
|
|
222
|
+
const records = await this._collectionOperations.getAll();
|
|
223
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
224
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
225
|
+
results = Filtering.sortedDocuments(Array.from(results).slice(), this._orderBys);
|
|
226
|
+
}
|
|
227
|
+
if (opts.count !== undefined) {
|
|
228
|
+
results = Array.from(results).slice(0, opts.count);
|
|
229
|
+
}
|
|
230
|
+
const ids = Array.from(results).map((doc) => doc.id);
|
|
231
|
+
const updates = Array.from(results).map((doc) => update(doc.data));
|
|
232
|
+
return await this._collectionOperations.updateManyRecordsByIdsWithDifferentValues(ids, updates);
|
|
233
|
+
}
|
|
234
|
+
updateManyFromSync(update, opts = {}) {
|
|
235
|
+
const records = this._collectionOperations.getAllSync();
|
|
236
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
237
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
238
|
+
results = Filtering.sortedDocuments(Array.from(results).slice(), this._orderBys);
|
|
239
|
+
}
|
|
240
|
+
if (opts.count !== undefined) {
|
|
241
|
+
results = Array.from(results).slice(0, opts.count);
|
|
242
|
+
}
|
|
243
|
+
const ids = Array.from(results).map((doc) => doc.id);
|
|
244
|
+
const updates = Array.from(results).map((doc) => update(doc.data));
|
|
245
|
+
return this._collectionOperations.updateManyRecordsByIdsWithDifferentValuesSync(ids, updates);
|
|
246
|
+
}
|
|
247
|
+
// --- DELETE
|
|
248
|
+
async delete() {
|
|
249
|
+
const records = await this._collectionOperations.getAll();
|
|
250
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
251
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
252
|
+
results = Filtering.sortedDocuments(Array.from(results), this._orderBys);
|
|
253
|
+
}
|
|
254
|
+
const single = Array.from(results)[0];
|
|
255
|
+
if (single)
|
|
256
|
+
return ((await this._collectionOperations.deleteById(single.id)) ?? undefined);
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
deleteSync() {
|
|
260
|
+
const records = this._collectionOperations.getAllSync();
|
|
261
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
262
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
263
|
+
results = Filtering.sortedDocuments(Array.from(results), this._orderBys);
|
|
264
|
+
}
|
|
265
|
+
const single = Array.from(results)[0];
|
|
266
|
+
if (single)
|
|
267
|
+
return this._collectionOperations.deleteByIdSync(single.id) ?? undefined;
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
async deleteMany() {
|
|
271
|
+
const records = await this._collectionOperations.getAll();
|
|
272
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
273
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
274
|
+
results = Filtering.sortedDocuments(Array.from(results).slice(), this._orderBys);
|
|
275
|
+
}
|
|
276
|
+
const ids = Array.from(results).map((doc) => doc.id);
|
|
277
|
+
return await this._collectionOperations.deleteManyByIds(ids);
|
|
278
|
+
}
|
|
279
|
+
deleteManySync() {
|
|
280
|
+
const records = this._collectionOperations.getAllSync();
|
|
281
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
282
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
283
|
+
results = Filtering.sortedDocuments(Array.from(results).slice(), this._orderBys);
|
|
284
|
+
}
|
|
285
|
+
const ids = Array.from(results).map((doc) => doc.id);
|
|
286
|
+
return this._collectionOperations.deleteManyByIdsSync(ids);
|
|
287
|
+
}
|
|
288
|
+
// --- UPSERT
|
|
289
|
+
async upsert({ update, insert, }) {
|
|
290
|
+
const records = await this._collectionOperations.getAll();
|
|
291
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
292
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
293
|
+
results = Filtering.sortedDocuments(Array.from(results), this._orderBys);
|
|
294
|
+
}
|
|
295
|
+
const single = Array.from(results)[0];
|
|
296
|
+
if (single) {
|
|
297
|
+
return ((await this._collectionOperations.updateOneRecordById(single.id, update)) ?? undefined);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return (await this._collectionOperations.add(insert)) ?? undefined;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
upsertSync({ update, insert, }) {
|
|
304
|
+
const records = this._collectionOperations.getAllSync();
|
|
305
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
306
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
307
|
+
results = Filtering.sortedDocuments(Array.from(results), this._orderBys);
|
|
308
|
+
}
|
|
309
|
+
const single = Array.from(results)[0];
|
|
310
|
+
if (single) {
|
|
311
|
+
this._collectionOperations.updateOneRecordById(single.id, update);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
this._collectionOperations.add(insert);
|
|
315
|
+
}
|
|
316
|
+
return single;
|
|
317
|
+
}
|
|
318
|
+
// --- ADD IF ABSENT
|
|
319
|
+
async addIfAbsent(data) {
|
|
320
|
+
const records = await this._collectionOperations.getAll();
|
|
321
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
322
|
+
const record = Array.from(results)[0];
|
|
323
|
+
return record ?? (await this._collectionOperations.add(data));
|
|
324
|
+
}
|
|
325
|
+
addIfAbsentSync(data) {
|
|
326
|
+
const records = this._collectionOperations.getAllSync();
|
|
327
|
+
let results = Filtering.matchedDocuments(records, this._conditions);
|
|
328
|
+
const record = Array.from(results)[0];
|
|
329
|
+
return record ?? this._collectionOperations.addSync(data);
|
|
330
|
+
}
|
|
331
|
+
// --- TO CSV
|
|
332
|
+
toCSV() {
|
|
333
|
+
return Json.mapToCSV(this.getSync().map((doc) => doc.data));
|
|
334
|
+
}
|
|
335
|
+
// --- FILTER
|
|
336
|
+
_getRecords(records) {
|
|
337
|
+
let matchedRecords = Filtering.matchedDocuments(records, this._conditions);
|
|
338
|
+
if (Object.keys(this._orderBys).length > 0) {
|
|
339
|
+
matchedRecords = Filtering.sortedDocuments([...matchedRecords], this._orderBys);
|
|
340
|
+
}
|
|
341
|
+
matchedRecords = Filtering.skipAndTakeDocuments(matchedRecords, this._skip, this._take);
|
|
342
|
+
matchedRecords = Filtering.pickAndOmitDocuments(matchedRecords, this._pick, this._omit);
|
|
343
|
+
return [...matchedRecords];
|
|
344
|
+
}
|
|
345
|
+
toString() {
|
|
346
|
+
return `Executor(conditions: ${JSON.stringify(this._conditions)}, pick: ${Array.from(this._pick)}, omit: ${Array.from(this._omit)}, skip: ${this._skip}, take: ${this._take}, orderBys: ${JSON.stringify(this._orderBys)}, collection: ${this._collection})`;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Collection from "../collection";
|
|
2
|
+
export type RelationType = "oneToOne" | "oneToMany" | "manyToMany";
|
|
3
|
+
export default class Relation {
|
|
4
|
+
name: string;
|
|
5
|
+
localCollection: Collection;
|
|
6
|
+
localKey: string;
|
|
7
|
+
foreignCollection: Collection;
|
|
8
|
+
foreignKey: string;
|
|
9
|
+
type: RelationType;
|
|
10
|
+
constructor(params: {
|
|
11
|
+
name: string;
|
|
12
|
+
localCollection: Collection;
|
|
13
|
+
localKey: string;
|
|
14
|
+
foreignCollection: Collection;
|
|
15
|
+
foreignKey: string;
|
|
16
|
+
type: RelationType;
|
|
17
|
+
});
|
|
18
|
+
toJson(): {
|
|
19
|
+
name: string;
|
|
20
|
+
localCollection: Collection;
|
|
21
|
+
localKey: string;
|
|
22
|
+
foreignCollection: Collection;
|
|
23
|
+
foreignKey: string;
|
|
24
|
+
type: RelationType;
|
|
25
|
+
};
|
|
26
|
+
static fromJson(json: any): Relation;
|
|
27
|
+
toString(): string;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=relation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../../../../src/core/collection/query/relation.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AAEvC,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;AAEnE,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,UAAU,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,UAAU,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,YAAY,CAAC;gBAEP,MAAM,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,UAAU,CAAC;QAC5B,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,UAAU,CAAC;QAC9B,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,YAAY,CAAC;KACpB;IASD,MAAM;;;;;;;;IAWN,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,QAAQ;IAWpC,QAAQ,IAAI,MAAM;CAGnB"}
|