@naturalcycles/firestore-lib 1.3.0 → 1.4.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.
@@ -15,7 +15,7 @@ export declare class FirestoreDB extends BaseCommonDB implements CommonDB {
15
15
  getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], _opt?: FirestoreDBOptions): Promise<ROW[]>;
16
16
  runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<RunQueryResult<ROW>>;
17
17
  runFirestoreQuery<ROW extends ObjectWithId>(q: Query, _opt?: FirestoreDBOptions): Promise<ROW[]>;
18
- runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<number>;
18
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: FirestoreDBOptions): Promise<number>;
19
19
  streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
20
20
  saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: FirestoreDBSaveOptions<ROW>): Promise<void>;
21
21
  deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: FirestoreDBOptions): Promise<number>;
@@ -52,9 +52,10 @@ class FirestoreDB extends db_lib_1.BaseCommonDB {
52
52
  async runFirestoreQuery(q, _opt) {
53
53
  return this.querySnapshotToArray(await q.get());
54
54
  }
55
- async runQueryCount(q, opt) {
56
- const { rows } = await this.runQuery(q.select([]), opt);
57
- return rows.length;
55
+ async runQueryCount(q, _opt) {
56
+ const firestoreQuery = (0, query_util_1.dbQueryToFirestoreQuery)(q, this.cfg.firestore.collection(q.table));
57
+ const r = await firestoreQuery.count().get();
58
+ return r.data().count;
58
59
  }
59
60
  streamQuery(q, _opt) {
60
61
  const firestoreQuery = (0, query_util_1.dbQueryToFirestoreQuery)(q, this.cfg.firestore.collection(q.table));
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "engines": {
38
38
  "node": ">=14.15.0"
39
39
  },
40
- "version": "1.3.0",
40
+ "version": "1.4.0",
41
41
  "description": "Firestore implementation of CommonDB interface",
42
42
  "author": "Natural Cycles Team",
43
43
  "license": "MIT"
@@ -98,10 +98,11 @@ export class FirestoreDB extends BaseCommonDB implements CommonDB {
98
98
 
99
99
  override async runQueryCount<ROW extends ObjectWithId>(
100
100
  q: DBQuery<ROW>,
101
- opt?: FirestoreDBOptions,
101
+ _opt?: FirestoreDBOptions,
102
102
  ): Promise<number> {
103
- const { rows } = await this.runQuery(q.select([]), opt)
104
- return rows.length
103
+ const firestoreQuery = dbQueryToFirestoreQuery(q, this.cfg.firestore.collection(q.table))
104
+ const r = await firestoreQuery.count().get()
105
+ return r.data().count
105
106
  }
106
107
 
107
108
  override streamQuery<ROW extends ObjectWithId>(