ravendb
Version:
RavenDB client for Node.js
47 lines • 1.91 kB
JavaScript
import { Stopwatch } from "../../../Utility/Stopwatch.js";
import { FacetResult } from "./index.js";
import { FacetQueryCommand } from "../../Commands/FacetQueryCommand.js";
import { QueryOperation } from "../../Session/Operations/QueryOperation.js";
import { LazyAggregationQueryOperation } from "../../Session/Operations/Lazy/LazyAggregationQueryOperation.js";
export class AggregationQueryBase {
_session;
_query;
_duration;
constructor(session) {
this._session = session;
}
async execute() {
const command = this._getCommand();
this._duration = 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(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 FacetResult(), result);
results[facetResult.name] = facetResult;
}
this._session.registerIncludes(queryResult.includes);
QueryOperation.ensureIsAcceptable(queryResult, this._query.waitForNonStaleResults, this._duration, this._session);
return results;
}
_getCommand() {
this._query = this._getIndexQuery();
return new FacetQueryCommand(this._session, this._query, {
metadataOnly: false,
indexEntriesOnly: false
});
}
toString() {
return this._getIndexQuery(false).toString();
}
}
//# sourceMappingURL=AggregationQueryBase.js.map