dborm-mysql 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/db.js +9 -0
- package/base/err.js +1 -0
- package/package.json +1 -1
package/base/db.js
CHANGED
|
@@ -23,6 +23,12 @@ let logSql = (connection, rows, sql, startTime, logExecuteTime) => {
|
|
|
23
23
|
console.log(info);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
// 去掉报错信息行,只保留当前函数调用栈
|
|
27
|
+
let getCurrentStack = (currentStack) => {
|
|
28
|
+
// new Error().stack的格式是:Error: 错误信息\n at 函数名 (文件路径:行号:列号)... 去掉第一行即可获取当前函数的调用栈
|
|
29
|
+
return currentStack.split('\n').slice(1).join('\n');
|
|
30
|
+
};
|
|
31
|
+
|
|
26
32
|
module.exports = (dbConfig, {log, noConvertDbCodes, dbCode, logExecuteTime}) => {
|
|
27
33
|
let db = {
|
|
28
34
|
pool: null
|
|
@@ -90,6 +96,7 @@ module.exports = (dbConfig, {log, noConvertDbCodes, dbCode, logExecuteTime}) =>
|
|
|
90
96
|
};
|
|
91
97
|
|
|
92
98
|
db.query = function (sql, sqlParam, connection) {
|
|
99
|
+
let currentStack = new Error().stack;
|
|
93
100
|
let query;
|
|
94
101
|
return new Promise(function (resolve, reject) {
|
|
95
102
|
if(process.MYSQL_READ_ONLY && !sql.toLowerCase().trimLeft().startsWith('select')){
|
|
@@ -111,6 +118,7 @@ module.exports = (dbConfig, {log, noConvertDbCodes, dbCode, logExecuteTime}) =>
|
|
|
111
118
|
logSql(connection, rows, query.sql, startTime, logExecuteTime);
|
|
112
119
|
}
|
|
113
120
|
err.code = dbCode;
|
|
121
|
+
err.stack = err.stack + getCurrentStack(currentStack);
|
|
114
122
|
reject(err);
|
|
115
123
|
} else {
|
|
116
124
|
resolve(rows);
|
|
@@ -135,6 +143,7 @@ module.exports = (dbConfig, {log, noConvertDbCodes, dbCode, logExecuteTime}) =>
|
|
|
135
143
|
}
|
|
136
144
|
});
|
|
137
145
|
}).catch(function (err) {
|
|
146
|
+
err.stack = err.stack + getCurrentStack(currentStack);
|
|
138
147
|
reject(err);
|
|
139
148
|
});
|
|
140
149
|
}
|
package/base/err.js
CHANGED