@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
82 lines (80 loc) • 2.34 kB
JavaScript
import {
toClause
} from "./chunk-OKPGJD64.mjs";
import {
Property
} from "./chunk-GCY5A63A.mjs";
import {
tryTo
} from "./chunk-XAIHCZT4.mjs";
import {
ofGet
} from "./chunk-SJGQU3OG.mjs";
// src/sql/Column.ts
var Column = class extends Property {
constructor(owner, property, options) {
super(property, options);
this.owner = owner;
}
get count() {
return this.function("COUNT");
}
get max() {
return this.function("MAX");
}
get min() {
return this.function("MIN");
}
get sum() {
return this.function("SUM");
}
get average() {
return this.function("AVG");
}
get length() {
return this.function("LEN");
}
get asc() {
return this.format("$col ASC");
}
get desc() {
return this.format("$col DESC");
}
in = (source = {}) => tryTo(source).map((s) => s[this.property] ?? ofGet(this.options?.dflt)).map((v) => this.options?.convert?.to(v)).orElse();
out = (source = {}, key = "") => tryTo(source).map((s) => this.options?.convert?.from(s[key])).orElse();
function = (func) => this.format(`${func}($name)`);
format = (pattern) => new PatternColumn(this, pattern);
is = (value) => this.clause("=", value);
not = (value) => this.clause("<>", value);
like = (value) => this.clause("LIKE", `%${value}%`);
startsLike = (value) => this.clause("LIKE", `${value}%`);
endsLike = (value) => this.clause("LIKE", `%${value}`);
unlike = (value) => this.clause("NOT LIKE", `%${value}%`);
less = (value) => this.clause("<", value);
lessEqual = (value) => this.clause("<=", value);
greater = (value) => this.clause(">", value);
greaterEqual = (value) => this.clause(">=", value);
as = (as) => this.format(`$col AS ${as}`);
toString() {
return `${this.owner}.${this.property}`;
}
clause = (operator, value) => toClause(this, operator, value, this?.options?.convert);
};
var PatternColumn = class extends Column {
constructor(col, pattern) {
super(col.owner, col.property);
this.col = col;
this.pattern = pattern;
}
toString() {
return this.pattern.replace("$col", this.col.toString()).replace("$table", this.col.owner.toString).replace("$name", this.col.property);
}
};
var OrderColumn = class extends PatternColumn {
};
export {
Column,
PatternColumn,
OrderColumn
};
//# sourceMappingURL=chunk-EDR72POF.mjs.map