UNPKG

ravendb

Version:
51 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AggregationQueryBase = void 0; const Stopwatch_js_1 = require("../../../Utility/Stopwatch.js"); const index_js_1 = require("./index.js"); const FacetQueryCommand_js_1 = require("../../Commands/FacetQueryCommand.js"); const QueryOperation_js_1 = require("../../Session/Operations/QueryOperation.js"); const LazyAggregationQueryOperation_js_1 = require("../../Session/Operations/Lazy/LazyAggregationQueryOperation.js"); class AggregationQueryBase { _session; _query; _duration; constructor(session) { this._session = session; } async execute() { const command = this._getCommand(); this._duration = Stopwatch_js_1.Stopwatch.createStarted(); this._session.incrementRequestCount(); await this._session.requestExecutor.execute(command); return this._processResults(command.result); } executeLazy() { this._query = this._getIndexQuery(); return this._session .addLazyOperation(new LazyAggregationQueryOperation_js_1.LazyAggregationQueryOperation(this._session, this._query, this, (queryResult) => this._processResults(queryResult))); } _processResults(queryResult) { this.emit("afterQueryExecuted", queryResult); const results = {}; for (const result of queryResult.results) { const facetResult = Object.assign(new index_js_1.FacetResult(), result); results[facetResult.name] = facetResult; } this._session.registerIncludes(queryResult.includes); QueryOperation_js_1.QueryOperation.ensureIsAcceptable(queryResult, this._query.waitForNonStaleResults, this._duration, this._session); return results; } _getCommand() { this._query = this._getIndexQuery(); return new FacetQueryCommand_js_1.FacetQueryCommand(this._session, this._query, { metadataOnly: false, indexEntriesOnly: false }); } toString() { return this._getIndexQuery(false).toString(); } } exports.AggregationQueryBase = AggregationQueryBase; //# sourceMappingURL=AggregationQueryBase.js.map