@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
61 lines (60 loc) • 1.96 kB
JavaScript
import {
Gateway
} from "../chunk-66DVBO4C.mjs";
import {
toPageList
} from "../chunk-GYJHZJKL.mjs";
import {
ifDefined,
when
} from "../chunk-AVHYDITZ.mjs";
import "../chunk-EBIF6AMC.mjs";
import "../chunk-KCY4RPFR.mjs";
import "../chunk-SSROJBD5.mjs";
import "../chunk-S3NSPQ7M.mjs";
import "../chunk-NNA77YYC.mjs";
import "../chunk-SJGQU3OG.mjs";
import "../chunk-D5IYAIMK.mjs";
import "../chunk-PF7HDF6B.mjs";
import "../chunk-IXK47WKF.mjs";
import "../chunk-PIRWVOO2.mjs";
import {
isDefined
} from "../chunk-AAND4MKF.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