UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

31 lines (30 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteCommand = void 0; const builder_1 = require("@sqb/builder"); const command_helper_js_1 = require("./command.helper.js"); class DeleteCommand { // istanbul ignore next constructor() { throw new Error('This class is abstract'); } static async execute(args) { const { connection, entity, filter, params } = args; let where; if (filter) { where = (0, builder_1.And)(); await (0, command_helper_js_1.prepareFilter)(entity, filter, where); } const query = (0, builder_1.Delete)(entity.tableName + ' T'); if (where) query.where(...where._items); // Execute query const resp = await connection.execute(query, { params, objectRows: false, cursor: false, }); return (resp && resp.rowsAffected) || 0; } } exports.DeleteCommand = DeleteCommand;