@sqb/connect
Version:
Multi-dialect database connection framework written with TypeScript
31 lines (30 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CountCommand = void 0;
const builder_1 = require("@sqb/builder");
const command_helper_js_1 = require("./command.helper.js");
class CountCommand {
// 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, 'T');
}
const query = (0, builder_1.Select)((0, builder_1.Count)()).from(entity.tableName + ' T');
if (where)
query.where(where);
// Execute query
const resp = await connection.execute(query, {
params,
objectRows: false,
cursor: false,
});
return (resp && resp.rows && resp.rows[0][0]) || 0;
}
}
exports.CountCommand = CountCommand;