@naturalcycles/firestore-lib 1.4.1 → 1.4.3
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/firestore.db.d.ts +1 -0
- package/dist/firestore.db.js +19 -2
- package/package.json +1 -1
- package/src/firestore.db.ts +25 -6
package/dist/firestore.db.d.ts
CHANGED
package/dist/firestore.db.js
CHANGED
|
@@ -41,6 +41,13 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
|
|
|
41
41
|
}
|
|
42
42
|
// QUERY
|
|
43
43
|
async runQuery(q, opt) {
|
|
44
|
+
const idFilter = q._filters.find(f => f.name === 'id');
|
|
45
|
+
if (idFilter) {
|
|
46
|
+
const ids = Array.isArray(idFilter.val) ? idFilter.val : [idFilter.val];
|
|
47
|
+
return {
|
|
48
|
+
rows: await this.getByIds(q.table, ids, opt),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
44
51
|
const firestoreQuery = (0, query_util_1.dbQueryToFirestoreQuery)(q, this.cfg.firestore.collection(q.table));
|
|
45
52
|
let rows = await this.runFirestoreQuery(firestoreQuery, opt);
|
|
46
53
|
// Special case when projection query didn't specify 'id'
|
|
@@ -85,8 +92,15 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
|
|
|
85
92
|
}
|
|
86
93
|
// DELETE
|
|
87
94
|
async deleteByQuery(q, opt) {
|
|
88
|
-
|
|
89
|
-
const
|
|
95
|
+
let ids;
|
|
96
|
+
const idFilter = q._filters.find(f => f.name === 'id');
|
|
97
|
+
if (idFilter) {
|
|
98
|
+
ids = Array.isArray(idFilter.val) ? idFilter.val : [idFilter.val];
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const firestoreQuery = (0, query_util_1.dbQueryToFirestoreQuery)(q.select([]), this.cfg.firestore.collection(q.table));
|
|
102
|
+
ids = (await this.runFirestoreQuery(firestoreQuery)).map(obj => obj.id);
|
|
103
|
+
}
|
|
90
104
|
await this.deleteByIds(q.table, ids, opt);
|
|
91
105
|
return ids.length;
|
|
92
106
|
}
|
|
@@ -133,5 +147,8 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
|
|
|
133
147
|
async ping() {
|
|
134
148
|
// no-op now
|
|
135
149
|
}
|
|
150
|
+
async getTables() {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
136
153
|
}
|
|
137
154
|
exports.FirestoreDB = FirestoreDB;
|
package/package.json
CHANGED
package/src/firestore.db.ts
CHANGED
|
@@ -77,6 +77,14 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
77
77
|
q: DBQuery<ROW>,
|
|
78
78
|
opt?: FirestoreDBOptions,
|
|
79
79
|
): Promise<RunQueryResult<ROW>> {
|
|
80
|
+
const idFilter = q._filters.find(f => f.name === 'id')
|
|
81
|
+
if (idFilter) {
|
|
82
|
+
const ids: string[] = Array.isArray(idFilter.val) ? idFilter.val : [idFilter.val]
|
|
83
|
+
return {
|
|
84
|
+
rows: await this.getByIds(q.table, ids, opt),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
80
88
|
const firestoreQuery = dbQueryToFirestoreQuery(q, this.cfg.firestore.collection(q.table))
|
|
81
89
|
|
|
82
90
|
let rows = await this.runFirestoreQuery<ROW>(firestoreQuery, opt)
|
|
@@ -165,18 +173,25 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
165
173
|
q: DBQuery<ROW>,
|
|
166
174
|
opt?: FirestoreDBOptions,
|
|
167
175
|
): Promise<number> {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
)
|
|
172
|
-
|
|
176
|
+
let ids: ROW['id'][]
|
|
177
|
+
|
|
178
|
+
const idFilter = q._filters.find(f => f.name === 'id')
|
|
179
|
+
if (idFilter) {
|
|
180
|
+
ids = Array.isArray(idFilter.val) ? idFilter.val : [idFilter.val]
|
|
181
|
+
} else {
|
|
182
|
+
const firestoreQuery = dbQueryToFirestoreQuery(
|
|
183
|
+
q.select([]),
|
|
184
|
+
this.cfg.firestore.collection(q.table),
|
|
185
|
+
)
|
|
186
|
+
ids = (await this.runFirestoreQuery<ROW>(firestoreQuery)).map(obj => obj.id)
|
|
187
|
+
}
|
|
173
188
|
|
|
174
189
|
await this.deleteByIds(q.table, ids, opt)
|
|
175
190
|
|
|
176
191
|
return ids.length
|
|
177
192
|
}
|
|
178
193
|
|
|
179
|
-
|
|
194
|
+
async deleteByIds<ROW extends ObjectWithId>(
|
|
180
195
|
table: string,
|
|
181
196
|
ids: ROW['id'][],
|
|
182
197
|
_opt?: FirestoreDBOptions,
|
|
@@ -233,4 +248,8 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
|
|
|
233
248
|
override async ping(): Promise<void> {
|
|
234
249
|
// no-op now
|
|
235
250
|
}
|
|
251
|
+
|
|
252
|
+
override async getTables(): Promise<string[]> {
|
|
253
|
+
return []
|
|
254
|
+
}
|
|
236
255
|
}
|