ravendb
Version:
RavenDB client for Node.js
59 lines • 2.26 kB
JavaScript
import { throwError } from "../../Exceptions/index.js";
import { IndexQueryWithParameters } from "./IndexQueryWithParameters.js";
import { HashCalculator } from "./HashCalculator.js";
import { TypeUtil } from "../../Utility/TypeUtil.js";
import { JsonSerializer } from "../../Mapping/Json/Serializer.js";
export class IndexQuery extends IndexQueryWithParameters {
constructor(query) {
super();
this.query = query;
}
/**
* Indicates if query results should be read from cache (if cached previously)
* or added to cache (if there were no cached items prior)
*/
disableCaching;
getQueryHash(mapper) {
const hasher = new HashCalculator();
try {
hasher.write(this.query, mapper);
hasher.write(this.waitForNonStaleResults);
hasher.write(this.skipDuplicateChecking);
hasher.write(this.skipStatistics);
hasher.write(this.waitForNonStaleResultsTimeout || 0);
hasher.write(this.queryParameters, mapper);
return hasher.getHash();
}
catch (err) {
throwError("RavenException", "Unable to calculate hash", err);
}
}
}
export function writeIndexQuery(conventions, indexQuery) {
const result = {
Query: indexQuery.query
};
if (indexQuery.waitForNonStaleResults) {
result.WaitForNonStaleResults = indexQuery.waitForNonStaleResults;
}
if (!TypeUtil.isNullOrUndefined(indexQuery.waitForNonStaleResultsTimeout)) {
result.WaitForNonStaleResultsTimeout = indexQuery.waitForNonStaleResultsTimeout;
}
if (indexQuery.disableCaching) {
result.DisableCaching = indexQuery.disableCaching;
}
if (indexQuery.skipDuplicateChecking) {
result.SkipDuplicateChecking = indexQuery.skipDuplicateChecking;
}
if (!indexQuery.queryParameters) {
result.QueryParameters = null;
}
else {
result.QueryParameters = indexQuery.queryParameters;
}
if (indexQuery.projectionBehavior && indexQuery.projectionBehavior !== "Default") {
result.ProjectionBehavior = indexQuery.projectionBehavior;
}
return JsonSerializer.getDefault().serialize(result);
}
//# sourceMappingURL=IndexQuery.js.map