@bdkinc/knex-ibmi 0.3.1 → 0.3.5
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/README.md +1 -1
- package/dist/index.js +23 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -208,7 +208,7 @@ try {
|
|
|
208
208
|
|
|
209
209
|
await finished(data); // db queries are promises, we need to wait until resolved
|
|
210
210
|
|
|
211
|
-
// or we can iterate through each record
|
|
211
|
+
// or we can iterate through each record
|
|
212
212
|
for await (const record of data) {
|
|
213
213
|
console.log(record);
|
|
214
214
|
}
|
package/dist/index.js
CHANGED
|
@@ -449,35 +449,41 @@ var DB2Client = class extends import_knex.knex.Client {
|
|
|
449
449
|
this.printDebug(obj);
|
|
450
450
|
return obj;
|
|
451
451
|
}
|
|
452
|
-
_stream(connection, obj, stream, options) {
|
|
452
|
+
async _stream(connection, obj, stream, options) {
|
|
453
453
|
if (!obj.sql) throw new Error("A query is required to stream results");
|
|
454
454
|
return new Promise(async (resolve, reject) => {
|
|
455
|
-
stream.on("error",
|
|
456
|
-
if (err) {
|
|
457
|
-
connection.__knex__disposed = err;
|
|
458
|
-
}
|
|
459
|
-
reject(err);
|
|
460
|
-
});
|
|
455
|
+
stream.on("error", reject);
|
|
461
456
|
stream.on("end", resolve);
|
|
457
|
+
const cursor = await connection.query(obj.sql, obj.bindings, {
|
|
458
|
+
cursor: true,
|
|
459
|
+
fetchSize: options?.fetchSize || 1
|
|
460
|
+
});
|
|
462
461
|
const readableStream = new import_node_stream.Readable({
|
|
463
462
|
objectMode: true,
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
463
|
+
read() {
|
|
464
|
+
cursor.fetch((error, result) => {
|
|
465
|
+
if (error) {
|
|
466
|
+
console.log(error);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (!cursor.noData) {
|
|
470
|
+
this.push(result);
|
|
471
|
+
} else {
|
|
472
|
+
cursor.close((error2) => {
|
|
473
|
+
if (error2) {
|
|
474
|
+
console.log(error2);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
468
479
|
});
|
|
469
|
-
while (!cursor.noData) {
|
|
470
|
-
const result = await cursor.fetch();
|
|
471
|
-
this.push(result);
|
|
472
|
-
}
|
|
473
|
-
await cursor.close();
|
|
474
480
|
}
|
|
475
481
|
});
|
|
476
|
-
readableStream.pipe(stream);
|
|
477
482
|
readableStream.on("error", (err) => {
|
|
478
483
|
reject(err);
|
|
479
484
|
stream.emit("error", err);
|
|
480
485
|
});
|
|
486
|
+
readableStream.pipe(stream);
|
|
481
487
|
});
|
|
482
488
|
}
|
|
483
489
|
transaction(container, config, outerTx) {
|