UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

54 lines (52 loc) 1.34 kB
import { SqlQuery } from "./chunk-55SDDPJZ.mjs"; import { toList } from "./chunk-A7C3XND3.mjs"; import { ifGet } from "./chunk-SJGQU3OG.mjs"; // src/sql/Select.ts var Select = class extends SqlQuery { constructor(table, columns = toList()) { super(table); this.columns = columns; } ordered = toList(); grouped = toList(); _top = 0; _limit = 0; _offset = 0; from(t) { this.table = t ?? this.table; return this; } orderBy = (...ordered) => { this.ordered.add(ordered); return this; }; groupBy(...grouped) { this.grouped.add(grouped); return this; } top(t) { this._top = t; return this; } limit(l) { this._limit = l; return this; } offset(o) { this._offset = o; return this; } toString() { return `SELECT ` + ifGet(this._top, `TOP ${this._top} `, "") + ifGet(this.columns.length, this.columns.join(", "), "*") + ` FROM ${this.table}` + ifGet(this.clauses.length, ` WHERE ${this.clauses.join(" AND ")}`, "") + ifGet(this.grouped.length, ` GROUP BY ${this.grouped.join(", ")}`, "") + ifGet(this.ordered.length, ` ORDERED BY ${this.ordered.join(", ")}`, "") + ifGet(this._limit, ` LIMIT ${this._limit}`, "") + ifGet(this._offset, ` OFFSET ${this._offset};`, ";"); } }; export { Select }; //# sourceMappingURL=chunk-SSQRH66L.mjs.map