@configurator/ravendb
Version:
RavenDB client for Node.js
50 lines • 2.23 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AggregationQueryBase = void 0;
const Stopwatch_1 = require("../../../Utility/Stopwatch");
const _1 = require(".");
const FacetQueryCommand_1 = require("../../Commands/FacetQueryCommand");
const ObjectMapper_1 = require("../../../Mapping/ObjectMapper");
const QueryOperation_1 = require("../../Session/Operations/QueryOperation");
const LazyAggregationQueryOperation_1 = require("../../Session/Operations/Lazy/LazyAggregationQueryOperation");
class AggregationQueryBase {
constructor(session) {
this._session = session;
}
async execute() {
const command = this._getCommand();
this._duration = Stopwatch_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_1.LazyAggregationQueryOperation(this._session, this._query, this, (queryResult) => this._processResults(queryResult)));
}
_processResults(queryResult) {
this.emit("afterQueryExecuted", queryResult);
const results = {};
const mapper = new ObjectMapper_1.TypesAwareObjectMapper();
for (const result of queryResult.results) {
const facetResult = Object.assign(new _1.FacetResult(), result);
results[facetResult.name] = facetResult;
}
this._session.registerIncludes(queryResult.includes);
QueryOperation_1.QueryOperation.ensureIsAcceptable(queryResult, this._query.waitForNonStaleResults, this._duration, this._session);
return results;
}
_getCommand() {
this._query = this._getIndexQuery();
return new FacetQueryCommand_1.FacetQueryCommand(this._session, this._query, {
metadataOnly: false,
indexEntriesOnly: false
});
}
toString() {
return this._getIndexQuery(false).toString();
}
}
exports.AggregationQueryBase = AggregationQueryBase;
//# sourceMappingURL=AggregationQueryBase.js.map