mysql2-core 0.2.2 → 0.2.4
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/build.js +39 -39
- package/lib/index.js +162 -170
- package/package.json +2 -1
- package/src/build.ts +153 -153
- package/src/index.ts +481 -437
- package/src/metadata.ts +83 -66
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
4
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
5
|
s = arguments[i];
|
|
6
6
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -70,7 +70,7 @@ exports.createPool = createPool;
|
|
|
70
70
|
var PoolManager = (function () {
|
|
71
71
|
function PoolManager(pool) {
|
|
72
72
|
this.pool = pool;
|
|
73
|
-
this.driver =
|
|
73
|
+
this.driver = "mysql";
|
|
74
74
|
this.param = this.param.bind(this);
|
|
75
75
|
this.exec = this.exec.bind(this);
|
|
76
76
|
this.execBatch = this.execBatch.bind(this);
|
|
@@ -80,30 +80,30 @@ var PoolManager = (function () {
|
|
|
80
80
|
this.count = this.count.bind(this);
|
|
81
81
|
}
|
|
82
82
|
PoolManager.prototype.param = function (i) {
|
|
83
|
-
return
|
|
83
|
+
return "?";
|
|
84
84
|
};
|
|
85
85
|
PoolManager.prototype.exec = function (sql, args, ctx) {
|
|
86
|
-
var p =
|
|
86
|
+
var p = ctx ? ctx : this.pool;
|
|
87
87
|
return exec(p, sql, args);
|
|
88
88
|
};
|
|
89
89
|
PoolManager.prototype.execBatch = function (statements, firstSuccess, ctx) {
|
|
90
|
-
var p =
|
|
90
|
+
var p = ctx ? ctx : this.pool;
|
|
91
91
|
return execBatch(p, statements, firstSuccess);
|
|
92
92
|
};
|
|
93
93
|
PoolManager.prototype.query = function (sql, args, m, bools, ctx) {
|
|
94
|
-
var p =
|
|
94
|
+
var p = ctx ? ctx : this.pool;
|
|
95
95
|
return query(p, sql, args, m, bools);
|
|
96
96
|
};
|
|
97
97
|
PoolManager.prototype.queryOne = function (sql, args, m, bools, ctx) {
|
|
98
|
-
var p =
|
|
98
|
+
var p = ctx ? ctx : this.pool;
|
|
99
99
|
return queryOne(p, sql, args, m, bools);
|
|
100
100
|
};
|
|
101
101
|
PoolManager.prototype.execScalar = function (sql, args, ctx) {
|
|
102
|
-
var p =
|
|
102
|
+
var p = ctx ? ctx : this.pool;
|
|
103
103
|
return execScalar(p, sql, args);
|
|
104
104
|
};
|
|
105
105
|
PoolManager.prototype.count = function (sql, args, ctx) {
|
|
106
|
-
var p =
|
|
106
|
+
var p = ctx ? ctx : this.pool;
|
|
107
107
|
return count(p, sql, args);
|
|
108
108
|
};
|
|
109
109
|
return PoolManager;
|
|
@@ -129,7 +129,7 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
|
-
var query0 =
|
|
132
|
+
var query0 = "";
|
|
133
133
|
var queries_1 = [];
|
|
134
134
|
var l = statements.length;
|
|
135
135
|
for (var j = 0; j < l; j++) {
|
|
@@ -138,15 +138,15 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
138
138
|
query0 = mysql2_1.format(item.query, toArray(item.params));
|
|
139
139
|
}
|
|
140
140
|
else {
|
|
141
|
-
if (item.query.endsWith(
|
|
141
|
+
if (item.query.endsWith(";")) {
|
|
142
142
|
queries_1.push(mysql2_1.format(item.query, toArray(item.params)));
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
145
|
-
queries_1.push(mysql2_1.format(item.query +
|
|
145
|
+
queries_1.push(mysql2_1.format(item.query + ";", toArray(item.params)));
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
connection.
|
|
149
|
+
connection.execute(query0, function (er2a, results0) {
|
|
150
150
|
if (er2a) {
|
|
151
151
|
connection.rollback(function () {
|
|
152
152
|
return reject(er2a);
|
|
@@ -157,7 +157,7 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
157
157
|
return 0;
|
|
158
158
|
}
|
|
159
159
|
else {
|
|
160
|
-
connection.
|
|
160
|
+
connection.execute(queries_1.join(""), function (er2, results) {
|
|
161
161
|
if (er2) {
|
|
162
162
|
connection.rollback(function () {
|
|
163
163
|
return reject(er2);
|
|
@@ -172,7 +172,7 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
var c = 0;
|
|
175
|
-
c += results0.affectedRows + results.
|
|
175
|
+
c += results0.affectedRows + results.affectedRows;
|
|
176
176
|
return resolve(c);
|
|
177
177
|
}
|
|
178
178
|
});
|
|
@@ -199,14 +199,14 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
199
199
|
else {
|
|
200
200
|
var queries_2 = [];
|
|
201
201
|
statements.forEach(function (item) {
|
|
202
|
-
if (item.query.endsWith(
|
|
202
|
+
if (item.query.endsWith(";")) {
|
|
203
203
|
queries_2.push(mysql2_1.format(item.query, toArray(item.params)));
|
|
204
204
|
}
|
|
205
205
|
else {
|
|
206
|
-
queries_2.push(mysql2_1.format(item.query +
|
|
206
|
+
queries_2.push(mysql2_1.format(item.query + ";", toArray(item.params)));
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
|
-
connection.
|
|
209
|
+
connection.execute(queries_2.join(""), function (er2, results) {
|
|
210
210
|
if (er2) {
|
|
211
211
|
connection.rollback(function () {
|
|
212
212
|
buildError(er2);
|
|
@@ -221,7 +221,7 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
});
|
|
224
|
-
return resolve(results.
|
|
224
|
+
return resolve(results.affectedRows);
|
|
225
225
|
}
|
|
226
226
|
});
|
|
227
227
|
}
|
|
@@ -232,8 +232,8 @@ function execBatch(pool, statements, firstSuccess) {
|
|
|
232
232
|
}
|
|
233
233
|
exports.execBatch = execBatch;
|
|
234
234
|
function buildError(err) {
|
|
235
|
-
if (err.errno === 1062 && err.code ===
|
|
236
|
-
err.error =
|
|
235
|
+
if (err.errno === 1062 && err.code === "ER_DUP_ENTRY") {
|
|
236
|
+
err.error = "duplicate";
|
|
237
237
|
}
|
|
238
238
|
return err;
|
|
239
239
|
}
|
|
@@ -243,16 +243,16 @@ function exec(pool, sql, args) {
|
|
|
243
243
|
return __generator(this, function (_a) {
|
|
244
244
|
p = toArray(args);
|
|
245
245
|
return [2, new Promise(function (resolve, reject) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
246
|
+
return pool.execute(sql, p, function (err, res) {
|
|
247
|
+
if (err) {
|
|
248
|
+
buildError(err);
|
|
249
|
+
return reject(err);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return resolve(res.affectedRows);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
})];
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
258
|
}
|
|
@@ -263,35 +263,35 @@ function query(pool, sql, args, m, bools) {
|
|
|
263
263
|
return __generator(this, function (_a) {
|
|
264
264
|
p = toArray(args);
|
|
265
265
|
return [2, new Promise(function (resolve, reject) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
if (results.length > 0) {
|
|
272
|
-
var arrayResult = results.map(function (item) {
|
|
273
|
-
if (Array.isArray(item)) {
|
|
274
|
-
return formatData(fields, item);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
return item;
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
return resolve(handleResults(arrayResult, m, bools));
|
|
266
|
+
return pool.query(sql, p, function (err, results, fields) {
|
|
267
|
+
if (err) {
|
|
268
|
+
return reject(err);
|
|
281
269
|
}
|
|
282
270
|
else {
|
|
283
|
-
|
|
271
|
+
if (results.length > 0) {
|
|
272
|
+
var arrayResult = results.map(function (item) {
|
|
273
|
+
if (Array.isArray(item)) {
|
|
274
|
+
return formatData(fields, item);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
return item;
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return resolve(handleResults(arrayResult, m, bools));
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
resolve([]);
|
|
284
|
+
}
|
|
284
285
|
}
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
})];
|
|
286
|
+
});
|
|
287
|
+
})];
|
|
288
288
|
});
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
291
|
exports.query = query;
|
|
292
292
|
function queryOne(pool, sql, args, m, bools) {
|
|
293
293
|
return query(pool, sql, args, m, bools).then(function (r) {
|
|
294
|
-
return
|
|
294
|
+
return r && r.length > 0 ? r[0] : null;
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
297
|
exports.queryOne = queryOne;
|
|
@@ -316,7 +316,7 @@ function save(pool, obj, table, attrs, ver, buildParam, i) {
|
|
|
316
316
|
if (!s) {
|
|
317
317
|
return Promise.resolve(-1);
|
|
318
318
|
}
|
|
319
|
-
if (typeof pool ===
|
|
319
|
+
if (typeof pool === "function") {
|
|
320
320
|
return pool(s.query, s.params);
|
|
321
321
|
}
|
|
322
322
|
else {
|
|
@@ -326,7 +326,7 @@ function save(pool, obj, table, attrs, ver, buildParam, i) {
|
|
|
326
326
|
exports.save = save;
|
|
327
327
|
function saveBatch(pool, objs, table, attrs, ver, buildParam) {
|
|
328
328
|
var s = build_1.buildToSaveBatch(objs, table, attrs, ver, buildParam);
|
|
329
|
-
if (typeof pool ===
|
|
329
|
+
if (typeof pool === "function") {
|
|
330
330
|
return pool(s);
|
|
331
331
|
}
|
|
332
332
|
else {
|
|
@@ -345,7 +345,7 @@ function toArray(arr) {
|
|
|
345
345
|
p.push(null);
|
|
346
346
|
}
|
|
347
347
|
else {
|
|
348
|
-
if (typeof arr[i] ===
|
|
348
|
+
if (typeof arr[i] === "object") {
|
|
349
349
|
if (arr[i] instanceof Date) {
|
|
350
350
|
p.push(arr[i]);
|
|
351
351
|
}
|
|
@@ -398,13 +398,13 @@ function handleBool(objs, bools) {
|
|
|
398
398
|
var field = bools_1[_a];
|
|
399
399
|
if (field.name) {
|
|
400
400
|
var v = o[field.name];
|
|
401
|
-
if (typeof v !==
|
|
401
|
+
if (typeof v !== "boolean" && v != null && v !== undefined) {
|
|
402
402
|
var b = field.true;
|
|
403
403
|
if (b == null || b === undefined) {
|
|
404
|
-
o[field.name] =
|
|
404
|
+
o[field.name] = "1" == v || "T" == v || "Y" == v || "true" == v || "on" == v;
|
|
405
405
|
}
|
|
406
406
|
else {
|
|
407
|
-
o[field.name] =
|
|
407
|
+
o[field.name] = v == b ? true : false;
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
}
|
|
@@ -500,10 +500,10 @@ exports.getFields = getFields;
|
|
|
500
500
|
function buildFields(fields, all) {
|
|
501
501
|
var s = getFields(fields, all);
|
|
502
502
|
if (!s || s.length === 0) {
|
|
503
|
-
return
|
|
503
|
+
return "*";
|
|
504
504
|
}
|
|
505
505
|
else {
|
|
506
|
-
return s.join(
|
|
506
|
+
return s.join(",");
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
509
|
exports.buildFields = buildFields;
|
|
@@ -515,7 +515,7 @@ function getMapField(name, mp) {
|
|
|
515
515
|
if (!x) {
|
|
516
516
|
return name;
|
|
517
517
|
}
|
|
518
|
-
if (typeof x ===
|
|
518
|
+
if (typeof x === "string") {
|
|
519
519
|
return x;
|
|
520
520
|
}
|
|
521
521
|
return name;
|
|
@@ -536,7 +536,7 @@ var StringService = (function () {
|
|
|
536
536
|
StringService.prototype.load = function (key, max) {
|
|
537
537
|
var _this = this;
|
|
538
538
|
var s = "select " + this.column + " from " + this.table + " where " + this.column + " like ? order by " + this.column + " limit " + max;
|
|
539
|
-
return query(this.pool, s, [
|
|
539
|
+
return query(this.pool, s, ["" + key + "%"]).then(function (arr) {
|
|
540
540
|
return arr.map(function (i) { return i[_this.column]; });
|
|
541
541
|
});
|
|
542
542
|
};
|
|
@@ -546,9 +546,9 @@ var StringService = (function () {
|
|
|
546
546
|
}
|
|
547
547
|
var arr = [];
|
|
548
548
|
for (var i = 1; i <= values.length; i++) {
|
|
549
|
-
arr.push(
|
|
549
|
+
arr.push("(?)");
|
|
550
550
|
}
|
|
551
|
-
var s = "insert ignore into " + this.table + "(" + this.column + ")values" + arr.join(
|
|
551
|
+
var s = "insert ignore into " + this.table + "(" + this.column + ")values" + arr.join(",");
|
|
552
552
|
return exec(this.pool, s, values);
|
|
553
553
|
};
|
|
554
554
|
return StringService;
|
|
@@ -573,7 +573,7 @@ var MySQLWriter = (function () {
|
|
|
573
573
|
this.attributes = attributes;
|
|
574
574
|
this.oneIfSuccess = oneIfSuccess;
|
|
575
575
|
this.write = this.write.bind(this);
|
|
576
|
-
if (typeof pool ===
|
|
576
|
+
if (typeof pool === "function") {
|
|
577
577
|
this.exec = pool;
|
|
578
578
|
}
|
|
579
579
|
else {
|
|
@@ -598,7 +598,7 @@ var MySQLWriter = (function () {
|
|
|
598
598
|
if (stmt) {
|
|
599
599
|
if (this.exec) {
|
|
600
600
|
if (this.oneIfSuccess) {
|
|
601
|
-
return this.exec(stmt.query, stmt.params).then(function (ct) { return ct > 0 ? 1 : 0; });
|
|
601
|
+
return this.exec(stmt.query, stmt.params).then(function (ct) { return (ct > 0 ? 1 : 0); });
|
|
602
602
|
}
|
|
603
603
|
else {
|
|
604
604
|
return this.exec(stmt.query, stmt.params);
|
|
@@ -606,7 +606,7 @@ var MySQLWriter = (function () {
|
|
|
606
606
|
}
|
|
607
607
|
else {
|
|
608
608
|
if (this.oneIfSuccess) {
|
|
609
|
-
return exec(this.pool, stmt.query, stmt.params).then(function (ct) { return ct > 0 ? 1 : 0; });
|
|
609
|
+
return exec(this.pool, stmt.query, stmt.params).then(function (ct) { return (ct > 0 ? 1 : 0); });
|
|
610
610
|
}
|
|
611
611
|
else {
|
|
612
612
|
return exec(this.pool, stmt.query, stmt.params);
|
|
@@ -628,7 +628,7 @@ var MySQLStreamWriter = (function () {
|
|
|
628
628
|
this.size = 0;
|
|
629
629
|
this.write = this.write.bind(this);
|
|
630
630
|
this.flush = this.flush.bind(this);
|
|
631
|
-
if (typeof pool ===
|
|
631
|
+
if (typeof pool === "function") {
|
|
632
632
|
this.execBatch = pool;
|
|
633
633
|
}
|
|
634
634
|
else {
|
|
@@ -699,7 +699,7 @@ var MySQLBatchWriter = (function () {
|
|
|
699
699
|
this.attributes = attributes;
|
|
700
700
|
this.oneIfSuccess = oneIfSuccess;
|
|
701
701
|
this.write = this.write.bind(this);
|
|
702
|
-
if (typeof pool ===
|
|
702
|
+
if (typeof pool === "function") {
|
|
703
703
|
this.execute = pool;
|
|
704
704
|
}
|
|
705
705
|
else {
|
|
@@ -754,8 +754,8 @@ exports.MySQLBatchWriter = MySQLBatchWriter;
|
|
|
754
754
|
var MySQLChecker = (function () {
|
|
755
755
|
function MySQLChecker(pool, service, timeout) {
|
|
756
756
|
this.pool = pool;
|
|
757
|
-
this.timeout =
|
|
758
|
-
this.service =
|
|
757
|
+
this.timeout = timeout ? timeout : 4200;
|
|
758
|
+
this.service = service ? service : "mysql";
|
|
759
759
|
this.check = this.check.bind(this);
|
|
760
760
|
this.name = this.name.bind(this);
|
|
761
761
|
this.build = this.build.bind(this);
|
|
@@ -767,7 +767,7 @@ var MySQLChecker = (function () {
|
|
|
767
767
|
return __generator(this, function (_a) {
|
|
768
768
|
obj = {};
|
|
769
769
|
promise = new Promise(function (resolve, reject) {
|
|
770
|
-
_this.pool.query(
|
|
770
|
+
_this.pool.query("select current_time", function (err, result) {
|
|
771
771
|
if (err) {
|
|
772
772
|
return reject(err);
|
|
773
773
|
}
|
|
@@ -794,7 +794,7 @@ var MySQLChecker = (function () {
|
|
|
794
794
|
if (!data) {
|
|
795
795
|
data = {};
|
|
796
796
|
}
|
|
797
|
-
data[
|
|
797
|
+
data["error"] = err;
|
|
798
798
|
}
|
|
799
799
|
return data;
|
|
800
800
|
};
|
|
@@ -808,7 +808,7 @@ function promiseTimeOut(timeoutInMilliseconds, promise) {
|
|
|
808
808
|
setTimeout(function () {
|
|
809
809
|
reject("Timed out in: " + timeoutInMilliseconds + " milliseconds!");
|
|
810
810
|
}, timeoutInMilliseconds);
|
|
811
|
-
})
|
|
811
|
+
}),
|
|
812
812
|
]);
|
|
813
813
|
}
|
|
814
814
|
var Exporter = (function () {
|
|
@@ -836,56 +836,52 @@ var Exporter = (function () {
|
|
|
836
836
|
case 1:
|
|
837
837
|
stmt = _a.sent();
|
|
838
838
|
reader = this.connection.query(stmt.query, stmt.params);
|
|
839
|
-
reader.on(
|
|
839
|
+
reader.on("error", function (err) { return (er = err); });
|
|
840
840
|
if (this.map) {
|
|
841
|
-
reader.on(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
return [2];
|
|
852
|
-
});
|
|
841
|
+
reader.on("result", function (row) { return __awaiter(_this, void 0, void 0, function () {
|
|
842
|
+
var obj, data;
|
|
843
|
+
return __generator(this, function (_a) {
|
|
844
|
+
++idx;
|
|
845
|
+
this.connection.pause();
|
|
846
|
+
obj = mapOne(row, this.map);
|
|
847
|
+
data = this.format(obj);
|
|
848
|
+
this.write(data);
|
|
849
|
+
this.connection.resume();
|
|
850
|
+
return [2];
|
|
853
851
|
});
|
|
854
|
-
});
|
|
852
|
+
}); });
|
|
855
853
|
}
|
|
856
854
|
else {
|
|
857
|
-
reader.on(
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return [2];
|
|
867
|
-
});
|
|
855
|
+
reader.on("result", function (row) { return __awaiter(_this, void 0, void 0, function () {
|
|
856
|
+
var data;
|
|
857
|
+
return __generator(this, function (_a) {
|
|
858
|
+
++idx;
|
|
859
|
+
this.connection.pause();
|
|
860
|
+
data = this.format(row);
|
|
861
|
+
this.write(data);
|
|
862
|
+
this.connection.resume();
|
|
863
|
+
return [2];
|
|
868
864
|
});
|
|
869
|
-
});
|
|
865
|
+
}); });
|
|
870
866
|
}
|
|
871
867
|
return [2, new Promise(function (resolve, reject) {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
868
|
+
reader.on("end", function () {
|
|
869
|
+
_this.end();
|
|
870
|
+
if (er) {
|
|
871
|
+
reject(er);
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
_this.connection.end(function (err) {
|
|
875
|
+
if (err) {
|
|
876
|
+
reject(err);
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
resolve(idx);
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
})];
|
|
889
885
|
}
|
|
890
886
|
});
|
|
891
887
|
});
|
|
@@ -917,61 +913,57 @@ var ExportService = (function () {
|
|
|
917
913
|
case 1:
|
|
918
914
|
stmt = _a.sent();
|
|
919
915
|
reader = this.connection.query(stmt.query, stmt.params);
|
|
920
|
-
reader.on(
|
|
916
|
+
reader.on("error", function (err) { return (er = err); });
|
|
921
917
|
if (this.map) {
|
|
922
|
-
reader.on(
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
return [2];
|
|
933
|
-
});
|
|
918
|
+
reader.on("result", function (row) { return __awaiter(_this, void 0, void 0, function () {
|
|
919
|
+
var obj, data;
|
|
920
|
+
return __generator(this, function (_a) {
|
|
921
|
+
++idx;
|
|
922
|
+
this.connection.pause();
|
|
923
|
+
obj = mapOne(row, this.map);
|
|
924
|
+
data = this.formatter.format(obj);
|
|
925
|
+
this.writer.write(data);
|
|
926
|
+
this.connection.resume();
|
|
927
|
+
return [2];
|
|
934
928
|
});
|
|
935
|
-
});
|
|
929
|
+
}); });
|
|
936
930
|
}
|
|
937
931
|
else {
|
|
938
|
-
reader.on(
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
return [2];
|
|
948
|
-
});
|
|
932
|
+
reader.on("result", function (row) { return __awaiter(_this, void 0, void 0, function () {
|
|
933
|
+
var data;
|
|
934
|
+
return __generator(this, function (_a) {
|
|
935
|
+
++idx;
|
|
936
|
+
this.connection.pause();
|
|
937
|
+
data = this.formatter.format(row);
|
|
938
|
+
this.writer.write(data);
|
|
939
|
+
this.connection.resume();
|
|
940
|
+
return [2];
|
|
949
941
|
});
|
|
950
|
-
});
|
|
942
|
+
}); });
|
|
951
943
|
}
|
|
952
944
|
return [2, new Promise(function (resolve, reject) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
945
|
+
reader.on("end", function () {
|
|
946
|
+
if (_this.writer.end) {
|
|
947
|
+
_this.writer.end();
|
|
948
|
+
}
|
|
949
|
+
else if (_this.writer.flush) {
|
|
950
|
+
_this.writer.flush();
|
|
951
|
+
}
|
|
952
|
+
if (er) {
|
|
953
|
+
reject(er);
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
_this.connection.end(function (err) {
|
|
957
|
+
if (err) {
|
|
958
|
+
reject(err);
|
|
959
|
+
}
|
|
960
|
+
else {
|
|
961
|
+
resolve(idx);
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
});
|
|
966
|
+
})];
|
|
975
967
|
}
|
|
976
968
|
});
|
|
977
969
|
});
|
|
@@ -996,7 +988,7 @@ function mapOne(results, m) {
|
|
|
996
988
|
if (!k0) {
|
|
997
989
|
k0 = key;
|
|
998
990
|
}
|
|
999
|
-
obj2[k0] =
|
|
991
|
+
obj2[k0] = obj[key];
|
|
1000
992
|
}
|
|
1001
993
|
return obj2;
|
|
1002
994
|
}
|
|
@@ -1009,7 +1001,7 @@ function buildMap(attrs) {
|
|
|
1009
1001
|
var k = ks_2[_i];
|
|
1010
1002
|
var attr = attrs[k];
|
|
1011
1003
|
attr.name = k;
|
|
1012
|
-
var field =
|
|
1004
|
+
var field = attr.column ? attr.column : k;
|
|
1013
1005
|
var s = field.toLowerCase();
|
|
1014
1006
|
if (s !== k) {
|
|
1015
1007
|
mp[s] = k;
|
|
@@ -1029,9 +1021,9 @@ function select(table, attrs) {
|
|
|
1029
1021
|
var k = ks_3[_i];
|
|
1030
1022
|
var attr = attrs[k];
|
|
1031
1023
|
attr.name = k;
|
|
1032
|
-
var field =
|
|
1024
|
+
var field = attr.column ? attr.column : k;
|
|
1033
1025
|
cols.push(field);
|
|
1034
1026
|
}
|
|
1035
|
-
return "select " + cols.join(
|
|
1027
|
+
return "select " + cols.join(",") + " from " + table;
|
|
1036
1028
|
}
|
|
1037
1029
|
exports.select = select;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysql2-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "mysql2-core",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"clean:lib": "rimraf lib"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
+
"mysql2": "^3.16.3",
|
|
12
13
|
"tslint": "5.10.0",
|
|
13
14
|
"typescript": "^3.3.3333"
|
|
14
15
|
},
|