UNPKG

ravendb

Version:
47 lines 1.95 kB
import { Stopwatch } from "../../../Utility/Stopwatch.js"; import { QueryCommand } from "../../Commands/QueryCommand.js"; import { LazySuggestionQueryOperation } from "../../Session/Operations/Lazy/LazySuggestionQueryOperation.js"; import { QueryOperation } from "../../Session/Operations/QueryOperation.js"; import { ObjectUtil } from "../../../Utility/ObjectUtil.js"; export class SuggestionQueryBase { _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); } _processResults(queryResult) { this._invokeAfterQueryExecuted(queryResult); const results = {}; for (const result of queryResult.results) { const transformedResult = ObjectUtil.transformObjectKeys(result, { defaultTransform: ObjectUtil.camel }); results[transformedResult.name] = transformedResult; } QueryOperation.ensureIsAcceptable(queryResult, this._query.waitForNonStaleResults, this._duration, this._session); return results; } executeLazy() { this._query = this._getIndexQuery(); return this._session.addLazyOperation(new LazySuggestionQueryOperation(this._session, this._query, result => this._invokeAfterQueryExecuted(result), (result) => this._processResults(result))); } _getCommand() { this._query = this._getIndexQuery(); return new QueryCommand(this._session, this._query, { indexEntriesOnly: false, metadataOnly: false }); } toString() { return this._getIndexQuery(false).toString(); } } //# sourceMappingURL=SuggestionQueryBase.js.map