UNPKG

sipp

Version:

An Opinionated, High-Productivity MVC Web Framework in TypeScript

59 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Model = void 0; const objection_1 = require("objection"); const async_store_1 = require("../utils/async-store"); const validation_1 = require("../validation"); class Model extends objection_1.Model { static modelName() { return this.name.replace('Model', '').toLowerCase(); } static fillable() { return []; } static eager() { return this.relationMappings ? Object.keys(this.relationMappings).join(' ') : false; } static load(trx) { const eager = this.eager(); const query = this.query(trx); if (eager) { query.withGraphFetched(eager); } return query; } static resolveTransaction(trx) { if (trx) { return trx; } return async_store_1.hasStore() ? async_store_1.getStore().get("__TRANSACTION_KEY__") : undefined; } static query(trx) { return objection_1.Model.query.bind(this)(this.resolveTransaction(trx)); } static relatedQuery(relationName, trx) { return objection_1.Model.relatedQuery.bind(this)(relationName, this.resolveTransaction(trx)); } $query(trx) { return super.$query(Model.resolveTransaction(trx)); } $relatedQuery(relationName, trx) { return super.$relatedQuery(relationName, Model.resolveTransaction(trx)); } save() { return this.$query().insert(); } delete() { return this.$query().delete(); } validate() { return validation_1.validate(this); } validateSync() { return validation_1.validateSync(this); } } exports.Model = Model; //# sourceMappingURL=Model.js.map