UNPKG

@clickup/ent-framework

Version:

A PostgreSQL graph-database-alike library with microsharding and row-level security

48 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PgQueryLoad = void 0; const QueryBase_1 = require("../abstract/QueryBase"); const types_1 = require("../types"); const PgRunner_1 = require("./PgRunner"); class PgQueryLoad extends QueryBase_1.QueryBase { constructor() { super(...arguments); /** @ignore */ this.RUNNER_CLASS = PgRunnerLoad; } } exports.PgQueryLoad = PgQueryLoad; class PgRunnerLoad extends PgRunner_1.PgRunner { constructor(schema, client) { super(schema, client); this.op = "SELECT_BY_ID"; this.maxBatchSize = 1000; // Select by ID is cheap, so we can have much bigger load batches. this.default = null; // If no row is found, returns null. this.builder = { prefix: this.fmt("SELECT %SELECT_FIELDS FROM %T WHERE "), func: this.createOneOfBuilder(types_1.ID), suffix: this.fmt(""), }; } key(input) { return input; } async runSingle(input, annotations) { const sql = this.builder.prefix + this.builder.func([input]) + this.builder.suffix; const rows = await this.clientQuery(sql, annotations, 1); return rows[0]; } async runBatch(inputs, annotations) { const sql = this.builder.prefix + this.builder.func(inputs.values()) + this.builder.suffix; const rows = await this.clientQuery(sql, annotations, inputs.size); const outputs = new Map(); for (const row of rows) { outputs.set(row[types_1.ID], row); } return outputs; } } PgRunnerLoad.IS_WRITE = false; //# sourceMappingURL=PgQueryLoad.js.map