1 | ;
|
2 | /**
|
3 | * This file is part of the @egodigital/egoose distribution.
|
4 | * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
|
5 | *
|
6 | * @egodigital/egoose is free software: you can redistribute it and/or modify
|
7 | * it under the terms of the GNU Lesser General Public License as
|
8 | * published by the Free Software Foundation, version 3.
|
9 | *
|
10 | * @egodigital/egoose is distributed in the hope that it will be useful, but
|
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | * Lesser General Public License for more details.
|
14 | *
|
15 | * You should have received a copy of the GNU Lesser General Public License
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | */
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const statistics_1 = require("../statistics");
|
20 | /**
|
21 | * A basic statistic provider that loads data from Mongo database.
|
22 | */
|
23 | class MongoDatabaseStatisticProviderBase extends statistics_1.StatisticProviderBase {
|
24 | /**
|
25 | * Initializes a new instance of that class.
|
26 | *
|
27 | * @param {TDatabase} database The underlying database connection.
|
28 | */
|
29 | constructor(database) {
|
30 | super();
|
31 | this.database = database;
|
32 | }
|
33 | /** @inheritdoc */
|
34 | async close() {
|
35 | await this.database
|
36 | .disconnect();
|
37 | }
|
38 | /**
|
39 | * Counts all documents of a collection.
|
40 | *
|
41 | * @param {Function} modelSelector The function that returns the model to use.
|
42 | * @param {any} [filter] The optional filter.
|
43 | *
|
44 | * @return {Promise<number>} The promise that contains the number of documents.
|
45 | */
|
46 | async countDocuments(modelSelector, filter) {
|
47 | return await modelSelector(this.database)
|
48 | .find(filter)
|
49 | .countDocuments()
|
50 | .exec();
|
51 | }
|
52 | }
|
53 | exports.MongoDatabaseStatisticProviderBase = MongoDatabaseStatisticProviderBase;
|
54 | //# sourceMappingURL=statistics.js.map |
\ | No newline at end of file |