@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
58 lines • 1.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.RAW_PREPEND_HINT = void 0;
exports.buildHintQueries = buildHintQueries;
exports.RAW_PREPEND_HINT = "";
/**
* Builds query prologue queries for the given hints.
*
* In the resulting compound queries, the returned `queries` will become a part
* of the debug query text, and queriesDefault will be prepended and omitted
* from the debug query text.
*
* Also, if there is a special hint with key = "", the its value is appended as
* it is to the very beginning of the compound query sent. You can e.g. pass
* pg_hint_plan extension hints there.
*/
function buildHintQueries(hintsDefault = {}, hints = {}) {
const queriesDefault = [];
const queries = [];
const rawPrepend = hints[exports.RAW_PREPEND_HINT] ?? "";
for (const k in hintsDefault) {
const v = hintsDefault[k];
if (k === exports.RAW_PREPEND_HINT) {
continue;
}
else if (v === null || v === undefined) {
// Engine default or non-set.
continue;
}
else if (hints[k] !== undefined) {
// User sets this hint to some different value (or resets it).
continue;
}
else {
queriesDefault.push(buildHintQuery(k, v));
}
}
for (const k in hints) {
const v = hints[k];
if (k === exports.RAW_PREPEND_HINT) {
continue;
}
else if (v === null || v === undefined) {
// Engine default or non-set.
continue;
}
else {
queries.push(buildHintQuery(k, v));
}
}
return [rawPrepend, queriesDefault, queries];
}
function buildHintQuery(k, v) {
return k.toLowerCase() === "transaction"
? `SET LOCAL ${k} ${v}`
: `SET LOCAL ${k} TO ${v}`;
}
//# sourceMappingURL=buildHintQueries.js.map
;