UNPKG

snack-query-builder

Version:
42 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelectQueryBuilder = void 0; class SelectQueryBuilder { constructor(qb, wqb) { this.$top = 0; this.$fields = []; this.$queryBuilder = qb; this.$whereQueryBuilder = wqb; } select(...params) { if (params) { this.$fields = this.$fields.concat(...params); } return { where: () => this.$whereQueryBuilder, end: () => this.$queryBuilder, top: (top) => this.setTop(top), }; } end() { return this.$queryBuilder; } setTop(top) { this.$top = top; return { where: () => this.$whereQueryBuilder, end: () => this.$queryBuilder, }; } toString() { const spaces = this.$queryBuilder.getSpaces(); if (this.$fields.length === 0) { this.$fields.push('*'); } const fields = this.$fields.join(`,\n${''.padEnd(spaces, ' ')}`); const top = this.$top >= 1 ? `top ${this.$top}\n`.padEnd(spaces, ' ') : '\n'; return `${'select'.padEnd(spaces, ' ')}${top}${' '.padEnd(spaces, ' ')}${fields}`; } } exports.SelectQueryBuilder = SelectQueryBuilder; //# sourceMappingURL=select-query-builder.js.map