aozhiwei 4c2b34f678 1
2022-09-21 10:29:21 +08:00

47 lines
1.0 KiB
JavaScript

const utils = require('j7/utils');
const app = require('j7/app');
const error = require('j7/error');
const modelsFactory = require('./models/factory');
const serviceFactory = require('./services/factory');
const metaFactory = require('./metadata/factory');
class Session {
constructor(req, rsp) {
this.req = req;
this.rsp = rsp;
this.nowTime = utils.getUtcTime();
this.useConns = {};
}
async destory() {
if (this.user) {
await this.user.destory();
}
for (let key in this.useConns) {
this.useConns[key].release();
}
//console.log(new Error().stack);
this.useConns = null;
}
getMeta(name, key) {
return metaFactory.getMetaByKey(name, key);
}
callMetaStatic(name, method, ...args) {
return metaFactory.callMetaStatic(name, method, this, ...args);
}
traverseMetaList(name, cb) {
return metaFactory.traverseMetaList(name, cb);
}
callMetaFactory(name, ...args) {
return metaFactory[name](this, ...args);
}
}
module.exports = Session;