bellboy 6.6.1 → 6.6.2
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.
|
@@ -50,6 +50,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
50
50
|
};
|
|
51
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
52
|
exports.MssqlProcessor = void 0;
|
|
53
|
+
var stream_1 = require("stream");
|
|
53
54
|
var utils_1 = require("../utils");
|
|
54
55
|
var database_processor_1 = require("./base/database-processor");
|
|
55
56
|
var MssqlProcessor = /** @class */ (function (_super) {
|
|
@@ -59,15 +60,115 @@ var MssqlProcessor = /** @class */ (function (_super) {
|
|
|
59
60
|
}
|
|
60
61
|
MssqlProcessor.prototype.process = function (processStream) {
|
|
61
62
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
-
var db, dbRequest,
|
|
63
|
+
var done, readStream, data, db, dbRequest, processRows;
|
|
64
|
+
var _this = this;
|
|
63
65
|
return __generator(this, function (_a) {
|
|
64
66
|
switch (_a.label) {
|
|
65
|
-
case 0:
|
|
67
|
+
case 0:
|
|
68
|
+
done = false;
|
|
69
|
+
readStream = new stream_1.Readable({
|
|
70
|
+
objectMode: true,
|
|
71
|
+
read: function () {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var err_1, rowData;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
if (!(data.length === 0)) return [3 /*break*/, 6];
|
|
78
|
+
if (!!done) return [3 /*break*/, 5];
|
|
79
|
+
_a.label = 1;
|
|
80
|
+
case 1:
|
|
81
|
+
_a.trys.push([1, 3, , 4]);
|
|
82
|
+
return [4 /*yield*/, processRows()];
|
|
83
|
+
case 2:
|
|
84
|
+
_a.sent();
|
|
85
|
+
return [3 /*break*/, 4];
|
|
86
|
+
case 3:
|
|
87
|
+
err_1 = _a.sent();
|
|
88
|
+
this.emit('error', err_1);
|
|
89
|
+
return [3 /*break*/, 4];
|
|
90
|
+
case 4: return [3 /*break*/, 6];
|
|
91
|
+
case 5: return [2 /*return*/, this.push(null)];
|
|
92
|
+
case 6:
|
|
93
|
+
rowData = data.shift() || null;
|
|
94
|
+
this.push(rowData);
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
data = [];
|
|
102
|
+
return [4 /*yield*/, utils_1.getDb(this.connection, 'mssql')];
|
|
66
103
|
case 1:
|
|
67
104
|
db = _a.sent();
|
|
68
105
|
dbRequest = db.request();
|
|
69
|
-
|
|
106
|
+
dbRequest.on('error', function (err) {
|
|
107
|
+
if (err.code !== 'ECANCEL') {
|
|
108
|
+
readStream.emit('error', err);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
readStream.on('close', function () {
|
|
112
|
+
dbRequest.cancel();
|
|
113
|
+
});
|
|
114
|
+
dbRequest.stream = true;
|
|
70
115
|
dbRequest.query(this.query);
|
|
116
|
+
processRows = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
117
|
+
var _this = this;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
120
|
+
function removeListeners() {
|
|
121
|
+
dbRequest.removeListener('row', onRow);
|
|
122
|
+
dbRequest.removeListener('done', onDone);
|
|
123
|
+
dbRequest.removeListener('error', onError);
|
|
124
|
+
}
|
|
125
|
+
function onRow(row) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
data.push(row);
|
|
129
|
+
if (data.length >= 1000) {
|
|
130
|
+
dbRequest.pause();
|
|
131
|
+
removeListeners();
|
|
132
|
+
resolve();
|
|
133
|
+
}
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function onDone() {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
done = true;
|
|
142
|
+
removeListeners();
|
|
143
|
+
resolve();
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function onError(err) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
removeListeners();
|
|
152
|
+
reject(err);
|
|
153
|
+
return [2 /*return*/];
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
;
|
|
159
|
+
;
|
|
160
|
+
;
|
|
161
|
+
;
|
|
162
|
+
dbRequest.on('row', onRow);
|
|
163
|
+
dbRequest.on('done', onDone);
|
|
164
|
+
dbRequest.on('error', onError);
|
|
165
|
+
dbRequest.resume();
|
|
166
|
+
return [2 /*return*/];
|
|
167
|
+
});
|
|
168
|
+
}); })];
|
|
169
|
+
});
|
|
170
|
+
}); };
|
|
171
|
+
dbRequest.pause();
|
|
71
172
|
return [4 /*yield*/, processStream(readStream)];
|
|
72
173
|
case 2:
|
|
73
174
|
_a.sent();
|