@naturalcycles/mysql-lib 3.16.2 → 3.16.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/dist/mysql.db.js CHANGED
@@ -173,8 +173,19 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
173
173
  }
174
174
  if (this.cfg.logSQL)
175
175
  this.cfg.logger.log(`stream: ${sql}`);
176
- // return this.streamSQL(sql, opt)
177
- return this.pool().query(sql).stream().map(row => (0, js_lib_1._filterUndefinedValues)(row, true));
176
+ // todo: this is nice, but `mysql` package uses `readable-stream@2` which is not compatible with `node:stream` iterable helpers
177
+ // return (this.pool().query(sql).stream() as ReadableTyped<ROW>).map(row =>
178
+ // _filterUndefinedValues(row, true),
179
+ // )
180
+ return this.pool()
181
+ .query(sql)
182
+ .stream()
183
+ .pipe(new node_stream_1.Transform({
184
+ objectMode: true,
185
+ transform(row, _encoding, cb) {
186
+ cb(null, (0, js_lib_1._filterUndefinedValues)(row, true));
187
+ },
188
+ }));
178
189
  }
179
190
  // SAVE
180
191
  async saveBatch(table, rowsInput, opt = {}) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MySQLKeyValueDB = void 0;
4
+ const node_stream_1 = require("node:stream");
4
5
  const db_lib_1 = require("@naturalcycles/db-lib");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
7
  const mysql_db_1 = require("./mysql.db");
@@ -67,7 +68,18 @@ class MySQLKeyValueDB {
67
68
  sql += ` LIMIT ${limit}`;
68
69
  if (this.cfg.logSQL)
69
70
  this.db.cfg.logger.log(`stream: ${sql}`);
70
- return this.db.pool().query(sql).stream().map(row => row.id);
71
+ // todo: this is nice, but `mysql` package uses `readable-stream@2` which is not compatible with `node:stream` iterable helpers
72
+ // return (this.db.pool().query(sql).stream() as ReadableTyped<ObjectWithId>).map(row => row.id)
73
+ return this.db
74
+ .pool()
75
+ .query(sql)
76
+ .stream()
77
+ .pipe(new node_stream_1.Transform({
78
+ objectMode: true,
79
+ transform(row, _encoding, cb) {
80
+ cb(null, row.id);
81
+ },
82
+ }));
71
83
  }
72
84
  streamValues(table, limit) {
73
85
  let sql = `SELECT v FROM ${table}`;
package/package.json CHANGED
@@ -9,17 +9,17 @@
9
9
  "lbt": "dev-lib lbt"
10
10
  },
11
11
  "dependencies": {
12
- "@naturalcycles/db-lib": "^9.1.0",
13
- "@naturalcycles/js-lib": "^14.47.0",
14
- "@naturalcycles/nodejs-lib": "^13.1.0",
15
- "@types/mysql": "^2.15.19",
16
- "mysql": "^2.17.1"
12
+ "@naturalcycles/db-lib": "^9",
13
+ "@naturalcycles/js-lib": "^14",
14
+ "@naturalcycles/nodejs-lib": "^13",
15
+ "@types/mysql": "^2",
16
+ "mysql": "^2"
17
17
  },
18
18
  "devDependencies": {
19
- "@naturalcycles/dev-lib": "^15.18.0",
20
- "@types/node": "^22.7.4",
21
- "dotenv": "^16.0.0",
22
- "jest": "^29.0.0"
19
+ "@naturalcycles/dev-lib": "^15",
20
+ "@types/node": "^22",
21
+ "dotenv": "^16",
22
+ "jest": "^29"
23
23
  },
24
24
  "files": [
25
25
  "dist",
@@ -39,9 +39,9 @@
39
39
  "url": "https://github.com/NaturalCycles/mysql-lib"
40
40
  },
41
41
  "engines": {
42
- "node": ">=20.13.0"
42
+ "node": ">=22.12.0"
43
43
  },
44
- "version": "3.16.2",
44
+ "version": "3.16.3",
45
45
  "description": "MySQL client implementing CommonDB interface",
46
46
  "keywords": [
47
47
  "mysql",
package/src/mysql.db.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Readable } from 'node:stream'
1
+ import { Readable, Transform } from 'node:stream'
2
2
  import { promisify } from 'node:util'
3
3
  import {
4
4
  BaseCommonDB,
@@ -277,10 +277,21 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
277
277
 
278
278
  if (this.cfg.logSQL) this.cfg.logger.log(`stream: ${sql}`)
279
279
 
280
- // return this.streamSQL(sql, opt)
281
- return (this.pool().query(sql).stream() as ReadableTyped<ROW>).map(row =>
282
- _filterUndefinedValues(row, true),
283
- )
280
+ // todo: this is nice, but `mysql` package uses `readable-stream@2` which is not compatible with `node:stream` iterable helpers
281
+ // return (this.pool().query(sql).stream() as ReadableTyped<ROW>).map(row =>
282
+ // _filterUndefinedValues(row, true),
283
+ // )
284
+ return this.pool()
285
+ .query(sql)
286
+ .stream()
287
+ .pipe(
288
+ new Transform({
289
+ objectMode: true,
290
+ transform(row: ROW, _encoding, cb) {
291
+ cb(null, _filterUndefinedValues(row, true))
292
+ },
293
+ }),
294
+ )
284
295
  }
285
296
 
286
297
  // SAVE
@@ -1,3 +1,4 @@
1
+ import { Transform } from 'node:stream'
1
2
  import {
2
3
  CommonDBCreateOptions,
3
4
  CommonKeyValueDB,
@@ -88,7 +89,20 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
88
89
  if (limit) sql += ` LIMIT ${limit}`
89
90
  if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
90
91
 
91
- return (this.db.pool().query(sql).stream() as ReadableTyped<ObjectWithId>).map(row => row.id)
92
+ // todo: this is nice, but `mysql` package uses `readable-stream@2` which is not compatible with `node:stream` iterable helpers
93
+ // return (this.db.pool().query(sql).stream() as ReadableTyped<ObjectWithId>).map(row => row.id)
94
+ return this.db
95
+ .pool()
96
+ .query(sql)
97
+ .stream()
98
+ .pipe(
99
+ new Transform({
100
+ objectMode: true,
101
+ transform(row: ObjectWithId, _encoding, cb) {
102
+ cb(null, row.id)
103
+ },
104
+ }),
105
+ )
92
106
  }
93
107
 
94
108
  streamValues(table: string, limit?: number): ReadableTyped<Buffer> {