UNPKG

@clickup/ent-framework

Version:

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

44 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PgQueryDeleteWhere = void 0; const QueryBase_1 = require("../abstract/QueryBase"); const misc_1 = require("../internal/misc"); const types_1 = require("../types"); const PgRunner_1 = require("./PgRunner"); class PgQueryDeleteWhere extends QueryBase_1.QueryBase { constructor() { super(...arguments); /** @ignore */ this.RUNNER_CLASS = PgRunnerDeleteWhere; } } exports.PgQueryDeleteWhere = PgQueryDeleteWhere; class PgRunnerDeleteWhere extends PgRunner_1.PgRunner { constructor(schema, client) { super(schema, client); this.op = "DELETE_WHERE"; this.maxBatchSize = 1; this.default = []; // This runner doesn't support batching. this.runBatch = undefined; this.builder = this.createWhereBuilder({ prefix: this.fmt("DELETE FROM %T "), suffix: this.fmt(` RETURNING %PK AS ${types_1.ID}`), }); } key(input) { // Coalesce equal delete queries. const json = JSON.stringify(input); return (0, misc_1.stringHash)(json); } async runSingle(input, annotations) { if (!(input[types_1.ID] instanceof Array)) { throw Error(`Field ${types_1.ID} must be an array of IDs in ${this.op} query (for safety)`); } const sql = this.builder.prefix + this.builder.func(input) + this.builder.suffix; const rows = await this.clientQuery(sql, annotations, input[types_1.ID].length); return rows.map((row) => row[types_1.ID]); } } PgRunnerDeleteWhere.IS_WRITE = true; //# sourceMappingURL=PgQueryDeleteWhere.js.map