@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
49 lines • 1.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PgQueryLoadBy = void 0;
const QueryBase_1 = require("../abstract/QueryBase");
const PgRunner_1 = require("./PgRunner");
class PgQueryLoadBy extends QueryBase_1.QueryBase {
constructor() {
super(...arguments);
/** @ignore */
this.RUNNER_CLASS = PgRunnerLoadBy;
}
}
exports.PgQueryLoadBy = PgQueryLoadBy;
class PgRunnerLoadBy extends PgRunner_1.PgRunner {
constructor(schema, client) {
super(schema, client);
this.op = "SELECT_UNIQ";
this.maxBatchSize = 200; // Select by unique key is cheap, so we can have much bigger load batches to accumulate more data from e.g. Shard 0 for the next multi-Shard requests.
this.default = null; // If no row is found, returns null.
this.builders = this.createWhereBuildersFieldsEq({
prefix: this.fmt("SELECT %SELECT_FIELDS FROM %T "),
fields: this.schema.uniqueKey,
suffix: this.fmt(""),
});
}
key(input) {
return JSON.stringify(this.schema.uniqueKey.map((field) => input[field]));
}
async runSingle(input, annotations) {
const sql = this.builders.plain.prefix +
this.builders.plain.func([["", input]]) +
this.builders.plain.suffix;
const rows = await this.clientQuery(sql, annotations, 1);
return rows[0];
}
async runBatch(inputs, annotations) {
const sql = this.builders.optimized.prefix +
this.builders.optimized.func(inputs) +
this.builders.optimized.suffix;
const rows = await this.clientQuery(sql, annotations, inputs.size);
const output = new Map();
for (const row of rows) {
output.set(this.key(row), row);
}
return output;
}
}
PgRunnerLoadBy.IS_WRITE = false;
//# sourceMappingURL=PgQueryLoadBy.js.map