UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

72 lines (71 loc) 2.28 kB
import { Gateway } from "../chunk-7ULNXC33.mjs"; import { toPageList } from "../chunk-TORB7XB3.mjs"; import { when } from "../chunk-XAIHCZT4.mjs"; import "../chunk-OFGI5FLG.mjs"; import "../chunk-NCEWAKOZ.mjs"; import "../chunk-Q3WMGUO2.mjs"; import "../chunk-5HENJTR6.mjs"; import "../chunk-FKZ4MOTX.mjs"; import "../chunk-WSBULPUZ.mjs"; import "../chunk-JVDKV5HE.mjs"; import "../chunk-WTFW6DLP.mjs"; import "../chunk-NDCIZJXB.mjs"; import "../chunk-MCCIBDEH.mjs"; import "../chunk-H2762RTS.mjs"; import "../chunk-A7C3XND3.mjs"; import { ifDefined } from "../chunk-JSON7A4X.mjs"; import "../chunk-CO2AFYVD.mjs"; import "../chunk-BDA5LB4S.mjs"; import "../chunk-SJGQU3OG.mjs"; import "../chunk-ZHXKBOK2.mjs"; import "../chunk-ZPNFXK7Y.mjs"; import "../chunk-DXQSIBC7.mjs"; import "../chunk-PIRWVOO2.mjs"; import { isDefined } from "../chunk-DEJ7A5PY.mjs"; import "../chunk-4N72FQFX.mjs"; // src/sql/TableGateway.ts var TableGateway = class extends Gateway { constructor(table, provider = table.db.provide()) { super(); this.table = table; this.provider = provider; } provide = ({ provider } = {}) => provider ?? this.provider; all(options) { return this.provide(options).query(this.table.select()).then( (js) => toPageList( js.map((j) => this.table.in(j)), options ) ); } byId(id, options) { return this.provide(options).query(this.table.select().where(this.table.id.is(id))).then((js) => js.first()).then((j) => ifDefined(j, this.table.in(j))); } exists(id, options) { return this.byId(id).then((j) => isDefined(j)); } add(item, options) { return this.provide(options).query(this.table.insert(item)).then((js) => when(js.first()).not.isDefined.reject(`Could not add items with id ${item.id}`)).then((j) => this.table.in(j)); } remove(id, options) { return this.provide(options).command(this.table.delete().where(this.table.id.is(id))).then(() => true); } update(item, options) { return this.provide(options).query(this.table.update(item).where(this.table.id.is(item.id))).then((js) => when(js.first()).not.isDefined.reject(`Could not update item with id ${item.id}`)).then((j) => this.table.in(j)); } }; export { TableGateway }; //# sourceMappingURL=TableGateway.mjs.map