ztechno_core 0.0.34 → 0.0.36
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/lib/sql_service.d.ts +1 -0
- package/lib/sql_service.js +16 -12
- package/lib/user_service.js +1 -1
- package/package.json +1 -1
package/lib/sql_service.d.ts
CHANGED
package/lib/sql_service.js
CHANGED
|
@@ -57,17 +57,8 @@ class ZSqlService {
|
|
|
57
57
|
this.databaseName = options.database;
|
|
58
58
|
this.pool = mysql.createPool(Object.assign({}, this.defaultPoolconfig, options));
|
|
59
59
|
this.pool.on('connection', (connection) => {
|
|
60
|
-
connection.config.queryFormat = function (query, values) {
|
|
61
|
-
|
|
62
|
-
return query;
|
|
63
|
-
}
|
|
64
|
-
return query.replace(
|
|
65
|
-
/\:(\w+)/g,
|
|
66
|
-
function (txt, key) {
|
|
67
|
-
return values.hasOwnProperty(key) ? this.escape(values[key]) : txt;
|
|
68
|
-
}.bind(this),
|
|
69
|
-
);
|
|
70
|
-
};
|
|
60
|
+
// connection.config.queryFormat = function (query, values) {
|
|
61
|
+
// }
|
|
71
62
|
connection.on('error', (err) => {
|
|
72
63
|
this.triggerEvent('err', err);
|
|
73
64
|
});
|
|
@@ -96,7 +87,12 @@ class ZSqlService {
|
|
|
96
87
|
const con = await this.getPoolConnection();
|
|
97
88
|
try {
|
|
98
89
|
const output = await new Promise((resolve, reject) => {
|
|
99
|
-
|
|
90
|
+
if (Array.isArray(params)) {
|
|
91
|
+
con.query(sql, params, (err, result) => (err ? reject(err) : resolve(result)));
|
|
92
|
+
} else {
|
|
93
|
+
sql = this.formatQueryParams(con, sql, params);
|
|
94
|
+
con.query(sql, (err, result) => (err ? reject(err) : resolve(result)));
|
|
95
|
+
}
|
|
100
96
|
});
|
|
101
97
|
con.release();
|
|
102
98
|
return output;
|
|
@@ -108,5 +104,13 @@ class ZSqlService {
|
|
|
108
104
|
throw err;
|
|
109
105
|
}
|
|
110
106
|
}
|
|
107
|
+
formatQueryParams(con, query, values) {
|
|
108
|
+
if (!values) {
|
|
109
|
+
return query;
|
|
110
|
+
}
|
|
111
|
+
return query.replace(/\:(\w+)/g, (txt, key) => {
|
|
112
|
+
return values.hasOwnProperty(key) ? con.escape(values[key]) : txt;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
111
115
|
}
|
|
112
116
|
exports.ZSqlService = ZSqlService;
|
package/lib/user_service.js
CHANGED