123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- class ConnectionContext {
- constructor(cc) {
- this.cn = cc.cn;
- this.dc = cc.dc;
- this.options = cc.options;
- this.db = cc.db;
- this.level = cc.level;
- this.txLevel = cc.txLevel;
- this.parentCtx = null;
- this.taskCtx = null;
- this.start = null;
- this.txCount = 0;
- }
- connect(db) {
- this.db = db;
- this.start = new Date();
- }
- disconnect(kill) {
- if (this.db) {
- const p = this.db.release(kill);
- this.db = null;
- return p;
- }
- }
- clone() {
- const obj = new ConnectionContext(this);
- obj.parent = this;
- obj.parentCtx = this.taskCtx;
- return obj;
- }
- get nextTxCount() {
- let txCurrent = this, txTop = this;
- while (txCurrent.parent) {
- txCurrent = txCurrent.parent;
- if (txCurrent.taskCtx && txCurrent.taskCtx.isTX) {
- txTop = txCurrent;
- }
- }
- return txTop.txCount++;
- }
- }
- module.exports = {ConnectionContext};
|