UNPKG

@clickup/ent-framework

Version:

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

45 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PgQueryIDGen = void 0; const QueryBase_1 = require("../abstract/QueryBase"); const misc_1 = require("../internal/misc"); const types_1 = require("../types"); const escapeIdent_1 = require("./helpers/escapeIdent"); const PgRunner_1 = require("./PgRunner"); class PgQueryIDGen extends QueryBase_1.QueryBase { constructor() { super(...arguments); /** @ignore */ this.RUNNER_CLASS = PgRunnerIDGen; } } exports.PgQueryIDGen = PgQueryIDGen; class PgRunnerIDGen extends PgRunner_1.PgRunner { constructor() { super(...arguments); this.idAutoInsert = (0, misc_1.nullthrows)(this.schema.table[types_1.ID].autoInsert, `Schema for ${this.name}.${types_1.ID} must have autoInsert attribute defined`); this.op = "ID_GEN"; this.maxBatchSize = 100; this.default = "never_happens"; // abstract property implementation } async runSingle(_input, annotations) { const sql = "SELECT " + this.idAutoInsert; const rows = await this.clientQuery(sql, annotations, 1); return Object.values(rows[0])[0]; } async runBatch(inputs, annotations) { const parts = []; for (const key of inputs.keys()) { parts.push(this.idAutoInsert + " AS " + (0, escapeIdent_1.escapeIdent)(key)); } const sql = "SELECT " + parts.join(", "); const rows = await this.clientQuery(sql, annotations, inputs.size); const outputs = new Map(); for (const [key, id] of Object.entries(rows[0])) { outputs.set(key, id); } return outputs; } } PgRunnerIDGen.IS_WRITE = true; //# sourceMappingURL=PgQueryIDGen.js.map