multi-db-orm 3.0.1 → 3.0.3
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/engines/hanadb.js +27 -33
- package/package.json +2 -2
package/engines/hanadb.js
CHANGED
|
@@ -2,7 +2,7 @@ const { MultiDbORM } = require("./multidb");
|
|
|
2
2
|
|
|
3
3
|
class HanaDB extends MultiDbORM {
|
|
4
4
|
db;
|
|
5
|
-
|
|
5
|
+
pool;
|
|
6
6
|
dataMap = {
|
|
7
7
|
id: "VARCHAR(50) NOT NULL PRIMARY KEY",
|
|
8
8
|
string: "NVARCHAR(4000)",
|
|
@@ -34,8 +34,8 @@ class HanaDB extends MultiDbORM {
|
|
|
34
34
|
idleTimeout: credentials.timeout || 60000,
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
|
-
this.
|
|
38
|
-
this.db = this.
|
|
37
|
+
this.pool = hana.createPool(this.conn_params);
|
|
38
|
+
this.db = this.pool;
|
|
39
39
|
this.dbType = "hana";
|
|
40
40
|
this.reqMade = 0;
|
|
41
41
|
}
|
|
@@ -44,24 +44,18 @@ class HanaDB extends MultiDbORM {
|
|
|
44
44
|
const that = this;
|
|
45
45
|
this.reqMade++;
|
|
46
46
|
return new Promise((resolve, reject) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
if (that.conn.state() == "disconnected") {
|
|
61
|
-
that.conn.connect(that.conn_params, onConnect);
|
|
62
|
-
} else {
|
|
63
|
-
onConnect();
|
|
64
|
-
}
|
|
47
|
+
var conn = this.pool.getConnection();
|
|
48
|
+
conn.exec(query, (err, result) => {
|
|
49
|
+
conn.disconnect();
|
|
50
|
+
if (err) {
|
|
51
|
+
reject(err);
|
|
52
|
+
} else {
|
|
53
|
+
resolve(result);
|
|
54
|
+
}
|
|
55
|
+
if (that.loglevel > 3) {
|
|
56
|
+
console.log("Query", query, "->", result);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
65
59
|
});
|
|
66
60
|
}
|
|
67
61
|
|
|
@@ -69,22 +63,22 @@ class HanaDB extends MultiDbORM {
|
|
|
69
63
|
this.metrics.get(modelname, filter, options);
|
|
70
64
|
let where = "";
|
|
71
65
|
for (const key in filter) {
|
|
72
|
-
where +=
|
|
66
|
+
where += `"${key}" = '${filter[key]}' AND `;
|
|
73
67
|
}
|
|
74
68
|
where += "1 = 1";
|
|
75
69
|
let sort = "";
|
|
76
70
|
if (options) {
|
|
77
71
|
if (options.apply) {
|
|
78
72
|
if (options.apply.ineq) {
|
|
79
|
-
where += ` AND ${options.apply.field} ${options.apply.ineq.op} '${options.apply.ineq.value}'`;
|
|
73
|
+
where += ` AND "${options.apply.field}" ${options.apply.ineq.op} '${options.apply.ineq.value}'`;
|
|
80
74
|
}
|
|
81
75
|
if (options.apply.sort) {
|
|
82
|
-
sort = `ORDER BY ${options.apply.field} ${options.apply.sort}`;
|
|
76
|
+
sort = `ORDER BY "${options.apply.field}" ${options.apply.sort}`;
|
|
83
77
|
}
|
|
84
78
|
} else if (options.sort) {
|
|
85
79
|
sort = "ORDER BY";
|
|
86
80
|
for (let i = 0; i < options.sort.length; i++) {
|
|
87
|
-
sort += ` ${options.sort[i].field} ${options.sort[i].order}`;
|
|
81
|
+
sort += ` "${options.sort[i].field}" ${options.sort[i].order}`;
|
|
88
82
|
if (i < options.sort.length - 1) {
|
|
89
83
|
sort += ", ";
|
|
90
84
|
}
|
|
@@ -108,7 +102,7 @@ class HanaDB extends MultiDbORM {
|
|
|
108
102
|
this.metrics.getOne(modelname, filter);
|
|
109
103
|
let where = "";
|
|
110
104
|
for (const key in filter) {
|
|
111
|
-
where +=
|
|
105
|
+
where += `"${key}" = '${filter[key]}' AND `;
|
|
112
106
|
}
|
|
113
107
|
where += "1 = 1";
|
|
114
108
|
const query = `SELECT * FROM ${modelname} WHERE ${where} LIMIT 1;`;
|
|
@@ -138,9 +132,9 @@ class HanaDB extends MultiDbORM {
|
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
if (key.toLowerCase().trim() === "id") {
|
|
141
|
-
cols +=
|
|
135
|
+
cols += `"${key}" ${type} PRIMARY KEY NOT NULL ,`;
|
|
142
136
|
} else {
|
|
143
|
-
cols +=
|
|
137
|
+
cols += `"${key}" ${type},`;
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
cols = cols.substring(0, cols.length - 1);
|
|
@@ -159,7 +153,7 @@ class HanaDB extends MultiDbORM {
|
|
|
159
153
|
let cols = "";
|
|
160
154
|
let vals = "";
|
|
161
155
|
for (const key in object) {
|
|
162
|
-
cols = cols +
|
|
156
|
+
cols = cols + `"${key}",`;
|
|
163
157
|
let val = object[key];
|
|
164
158
|
if (typeof val == "object") val = JSON.stringify(object[key]);
|
|
165
159
|
val = this.escapeSQLValue(val);
|
|
@@ -193,7 +187,7 @@ class HanaDB extends MultiDbORM {
|
|
|
193
187
|
let where = "";
|
|
194
188
|
let vals = "";
|
|
195
189
|
for (const key in filter) {
|
|
196
|
-
where +=
|
|
190
|
+
where += `"${key}" = '${filter[key]}' AND `;
|
|
197
191
|
}
|
|
198
192
|
for (const key in object) {
|
|
199
193
|
let val = object[key];
|
|
@@ -201,7 +195,7 @@ class HanaDB extends MultiDbORM {
|
|
|
201
195
|
val = JSON.stringify(object[key]);
|
|
202
196
|
val = this.escapeSQLValue(val);
|
|
203
197
|
|
|
204
|
-
vals +=
|
|
198
|
+
vals += `"${key}" = ${val},`;
|
|
205
199
|
}
|
|
206
200
|
where += "1 = 1";
|
|
207
201
|
vals = vals.slice(0, -1);
|
|
@@ -221,7 +215,7 @@ class HanaDB extends MultiDbORM {
|
|
|
221
215
|
|
|
222
216
|
let where = "";
|
|
223
217
|
for (const key in filter) {
|
|
224
|
-
where +=
|
|
218
|
+
where += `"${key}" = '${filter[key]}' AND `;
|
|
225
219
|
}
|
|
226
220
|
where += "1 = 1";
|
|
227
221
|
const query = `DELETE FROM ${modelname} WHERE ${where};`;
|
|
@@ -230,7 +224,7 @@ class HanaDB extends MultiDbORM {
|
|
|
230
224
|
|
|
231
225
|
closePool() {
|
|
232
226
|
return new Promise((resolve, reject) => {
|
|
233
|
-
this.
|
|
227
|
+
this.pool.disconnect((err) => {
|
|
234
228
|
if (err) {
|
|
235
229
|
reject(err);
|
|
236
230
|
if (this.loglevel > 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "multi-db-orm",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "CRUD , Backup , Restore and Migration library for multiple databases",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
"url": "https://github.com/shiveshnavin/multi-db-orm/issues"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/shiveshnavin/multi-db-orm#readme"
|
|
50
|
-
}
|
|
50
|
+
}
|