@thisisagile/easy-mongo
Version:
Add support for MongoDB
57 lines (56 loc) • 1.29 kB
JavaScript
import {
MongoProvider
} from "./chunk-KCYZXNN4.mjs";
import {
toMongoType
} from "./chunk-MZE7UWQC.mjs";
// src/Collection.ts
import {
asString,
Database,
Field,
LogicalCondition,
Mapper,
mappings,
ofGet,
toCondition,
toUuid
} from "@thisisagile/easy";
var Collection = class extends Mapper {
map = {
...mappings,
field: (name, options) => new Field(name, options)
};
id = this.map.field("id", { dflt: toUuid });
constructor(options = { startFrom: "source" }) {
super(options);
}
get db() {
return Database.Default;
}
get provider() {
return new MongoProvider(this);
}
where = (...conditions) => new LogicalCondition(
"and",
conditions.map((c) => ofGet(c, this))
).toJSON();
match = (condition) => ({ $match: ofGet(condition, this).toJSON() });
group = (...conditions) => new LogicalCondition(
"group",
conditions.map((c) => ofGet(c, this))
).toJSON();
google = (value) => toCondition("$text", "search", value);
search = (key) => this.map.field(asString(key));
sort = (...conditions) => conditions.reduce((cs, c) => {
cs[c.key] = c.value;
return cs;
}, {});
out(to = {}) {
return toMongoType(super.out(to));
}
};
export {
Collection
};
//# sourceMappingURL=Collection.mjs.map