@rws-framework/db 3.4.1 → 3.5.1

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.
@@ -64,6 +64,9 @@ declare class RWSModel<T> implements IModel {
64
64
  private checkRelDisabled;
65
65
  static setServices(services: IRWSModelServices): void;
66
66
  getDb(): DBService;
67
+ static count(where?: {
68
+ [k: string]: any;
69
+ }): Promise<number>;
67
70
  static getDb(): DBService;
68
71
  reload(): Promise<T | null>;
69
72
  }
@@ -262,6 +262,9 @@ class RWSModel {
262
262
  getDb() {
263
263
  return this.services.dbService;
264
264
  }
265
+ static async count(where = {}) {
266
+ return await this.services.dbService.count(this, where);
267
+ }
265
268
  static getDb() {
266
269
  return this.services.dbService;
267
270
  }
@@ -3,6 +3,7 @@ import { ITimeSeries } from '../types/ITimeSeries';
3
3
  import { IModel } from '../models/interfaces/IModel';
4
4
  import { IDbConfigHandler } from '../types/DbConfigHandler';
5
5
  import { IPaginationParams } from '../types/FindParams';
6
+ import { OpModelType } from '../models/interfaces/OpModelType';
6
7
  interface IDBClientCreate {
7
8
  dbUrl?: string;
8
9
  dbName?: string;
@@ -33,5 +34,8 @@ declare class DBService {
33
34
  createTimeSeriesCollection(collection_name: string): Promise<Collection<ITimeSeries>>;
34
35
  private getCollectionHandler;
35
36
  private setOpts;
37
+ count<T = any>(opModel: OpModelType<T>, where?: {
38
+ [k: string]: any;
39
+ }): Promise<number>;
36
40
  }
37
41
  export { DBService, IDBClientCreate };
@@ -206,5 +206,8 @@ class DBService {
206
206
  this.opts = opts;
207
207
  return this;
208
208
  }
209
+ async count(opModel, where = {}) {
210
+ return await this.getCollectionHandler(opModel._collection).count({ where });
211
+ }
209
212
  }
210
213
  exports.DBService = DBService;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/db",
3
3
  "private": false,
4
- "version": "3.4.1",
4
+ "version": "3.5.1",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -361,6 +361,10 @@ class RWSModel<T> implements IModel {
361
361
  return this.services.dbService;
362
362
  }
363
363
 
364
+ public static async count(where: {[k: string]: any} = {}): Promise<number>{
365
+ return await this.services.dbService.count(this as OpModelType<any>, where);
366
+ }
367
+
364
368
  public static getDb(): DBService
365
369
  {
366
370
  return this.services.dbService;
@@ -5,6 +5,7 @@ import { IModel } from '../models/interfaces/IModel';
5
5
  import chalk from 'chalk';
6
6
  import { IDbConfigHandler } from '../types/DbConfigHandler';
7
7
  import { IPaginationParams } from '../types/FindParams';
8
+ import { OpModelType } from '../models/interfaces/OpModelType';
8
9
 
9
10
  interface IDBClientCreate {
10
11
  dbUrl?: string;
@@ -287,6 +288,10 @@ class DBService {
287
288
  this.opts = opts;
288
289
  return this;
289
290
  }
291
+
292
+ public async count<T = any>(opModel: OpModelType<T>, where: {[k: string]: any} = {}): Promise<number>{
293
+ return await this.getCollectionHandler(opModel._collection).count({where});
294
+ }
290
295
  }
291
296
 
292
297
  export { DBService, IDBClientCreate };