ztechno_core 0.0.34 → 0.0.35

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.
@@ -31,5 +31,6 @@ export declare class ZSqlService {
31
31
  [key: string]: any;
32
32
  },
33
33
  ): Promise<T>;
34
+ private formatQueryParams;
34
35
  }
35
36
  export {};
@@ -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
- if (!values) {
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
- con.query(sql, params, (err, result) => (err ? reject(err) : resolve(result)));
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztechno_core",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "Core files for ztechno framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",