snack-query-builder
Version:
Query generator for SQL
37 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WhereQueryBuilder = void 0;
const conditional_query_builder_1 = require("./conditional-query-builder");
class WhereQueryBuilder extends conditional_query_builder_1.ConditionalQueryBuilder {
constructor(qb, gb, hv, or) {
super(qb);
this.$qb = qb;
this.$groupBy = gb;
this.$having = hv;
this.$orderBy = or;
}
groupBy(...fields) {
this.$groupBy.groupBy(fields);
return { end: () => this.end(), having: () => this.$having };
}
orderBy(...fields) {
this.$orderBy.orderBy(...fields);
return this.$qb;
}
end() {
return this.$queryBuilder;
}
toString() {
const spaces = this.$queryBuilder.getSpaces();
if (this.$conditions.length === 0) {
return '';
}
const conditions = this.$conditions.join(`\n${''.padStart(spaces, ' ')}`);
if (!this.checkParenthesesBalanced(conditions)) {
throw 'Parentheses are not balanced';
}
return `${'where'.padEnd(spaces, ' ')}${conditions}`;
}
}
exports.WhereQueryBuilder = WhereQueryBuilder;
//# sourceMappingURL=where-query-builder.js.map