@naturalcycles/mysql-lib 3.14.7 → 3.14.8
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 +1 -9
- package/dist/mysqlKeyValueDB.js +6 -31
- package/package.json +3 -3
- package/src/mysql.db.ts +4 -12
- package/src/mysqlKeyValueDB.ts +7 -38
package/dist/mysql.db.js
CHANGED
|
@@ -173,15 +173,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
173
173
|
if (this.cfg.logSQL)
|
|
174
174
|
this.cfg.logger.log(`stream: ${sql}`);
|
|
175
175
|
// return this.streamSQL(sql, opt)
|
|
176
|
-
return this.pool()
|
|
177
|
-
.query(sql)
|
|
178
|
-
.stream()
|
|
179
|
-
.pipe(new node_stream_1.Transform({
|
|
180
|
-
objectMode: true,
|
|
181
|
-
transform(row, _encoding, cb) {
|
|
182
|
-
cb(null, (0, js_lib_1._filterUndefinedValues)(row, true));
|
|
183
|
-
},
|
|
184
|
-
}));
|
|
176
|
+
return this.pool().query(sql).stream().map(row => (0, js_lib_1._filterUndefinedValues)(row, true));
|
|
185
177
|
}
|
|
186
178
|
// SAVE
|
|
187
179
|
async saveBatch(table, rowsInput, opt = {}) {
|
package/dist/mysqlKeyValueDB.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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");
|
|
5
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
5
|
const mysql_db_1 = require("./mysql.db");
|
|
7
6
|
class MySQLKeyValueDB {
|
|
@@ -63,16 +62,7 @@ class MySQLKeyValueDB {
|
|
|
63
62
|
sql += ` LIMIT ${limit}`;
|
|
64
63
|
if (this.cfg.logSQL)
|
|
65
64
|
this.db.cfg.logger.log(`stream: ${sql}`);
|
|
66
|
-
return this.db
|
|
67
|
-
.pool()
|
|
68
|
-
.query(sql)
|
|
69
|
-
.stream()
|
|
70
|
-
.pipe(new node_stream_1.Transform({
|
|
71
|
-
objectMode: true,
|
|
72
|
-
transform(row, _, cb) {
|
|
73
|
-
cb(null, row.id);
|
|
74
|
-
},
|
|
75
|
-
}));
|
|
65
|
+
return this.db.pool().query(sql).stream().map(row => row.id);
|
|
76
66
|
}
|
|
77
67
|
streamValues(table, limit) {
|
|
78
68
|
let sql = `SELECT v FROM ${table}`;
|
|
@@ -80,16 +70,7 @@ class MySQLKeyValueDB {
|
|
|
80
70
|
sql += ` LIMIT ${limit}`;
|
|
81
71
|
if (this.cfg.logSQL)
|
|
82
72
|
this.db.cfg.logger.log(`stream: ${sql}`);
|
|
83
|
-
return this.db
|
|
84
|
-
.pool()
|
|
85
|
-
.query(sql)
|
|
86
|
-
.stream()
|
|
87
|
-
.pipe(new node_stream_1.Transform({
|
|
88
|
-
objectMode: true,
|
|
89
|
-
transform(row, _, cb) {
|
|
90
|
-
cb(null, row.v);
|
|
91
|
-
},
|
|
92
|
-
}));
|
|
73
|
+
return this.db.pool().query(sql).stream().map(row => row.v);
|
|
93
74
|
}
|
|
94
75
|
streamEntries(table, limit) {
|
|
95
76
|
let sql = `SELECT id,v FROM ${table}`;
|
|
@@ -97,16 +78,10 @@ class MySQLKeyValueDB {
|
|
|
97
78
|
sql += ` LIMIT ${limit}`;
|
|
98
79
|
if (this.cfg.logSQL)
|
|
99
80
|
this.db.cfg.logger.log(`stream: ${sql}`);
|
|
100
|
-
return this.db
|
|
101
|
-
.
|
|
102
|
-
.
|
|
103
|
-
|
|
104
|
-
.pipe(new node_stream_1.Transform({
|
|
105
|
-
objectMode: true,
|
|
106
|
-
transform(row, _, cb) {
|
|
107
|
-
cb(null, [row.id, row.v]);
|
|
108
|
-
},
|
|
109
|
-
}));
|
|
81
|
+
return this.db.pool().query(sql).stream().map(row => [
|
|
82
|
+
row.id,
|
|
83
|
+
row.v,
|
|
84
|
+
]);
|
|
110
85
|
}
|
|
111
86
|
async beginTransaction() {
|
|
112
87
|
await this.db.runSQL({ sql: `BEGIN TRANSACTION` });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/mysql-lib",
|
|
3
3
|
"scripts": {
|
|
4
|
-
"prepare": "husky
|
|
4
|
+
"prepare": "husky"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@naturalcycles/db-lib": "^9.1.0",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"url": "https://github.com/NaturalCycles/mysql-lib"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
37
|
+
"node": ">=18.12.0"
|
|
38
38
|
},
|
|
39
|
-
"version": "3.14.
|
|
39
|
+
"version": "3.14.8",
|
|
40
40
|
"description": "MySQL client implementing CommonDB interface",
|
|
41
41
|
"keywords": [
|
|
42
42
|
"mysql",
|
package/src/mysql.db.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Readable
|
|
1
|
+
import { Readable } from 'node:stream'
|
|
2
2
|
import { promisify } from 'node:util'
|
|
3
3
|
import {
|
|
4
4
|
DBPatch,
|
|
@@ -278,17 +278,9 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
|
|
|
278
278
|
if (this.cfg.logSQL) this.cfg.logger.log(`stream: ${sql}`)
|
|
279
279
|
|
|
280
280
|
// return this.streamSQL(sql, opt)
|
|
281
|
-
return this.pool()
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
.pipe(
|
|
285
|
-
new Transform({
|
|
286
|
-
objectMode: true,
|
|
287
|
-
transform(row, _encoding, cb) {
|
|
288
|
-
cb(null, _filterUndefinedValues(row, true))
|
|
289
|
-
},
|
|
290
|
-
}),
|
|
291
|
-
)
|
|
281
|
+
return (this.pool().query(sql).stream() as ReadableTyped<ROW>).map(row =>
|
|
282
|
+
_filterUndefinedValues(row, true),
|
|
283
|
+
)
|
|
292
284
|
}
|
|
293
285
|
|
|
294
286
|
// SAVE
|
package/src/mysqlKeyValueDB.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Transform } from 'node:stream'
|
|
2
1
|
import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib'
|
|
3
|
-
import { pMap } from '@naturalcycles/js-lib'
|
|
2
|
+
import { ObjectWithId, pMap } from '@naturalcycles/js-lib'
|
|
4
3
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
5
4
|
import { QueryOptions } from 'mysql'
|
|
6
5
|
import { MysqlDB, MysqlDBCfg } from './mysql.db'
|
|
@@ -78,18 +77,7 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
|
|
|
78
77
|
if (limit) sql += ` LIMIT ${limit}`
|
|
79
78
|
if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
|
|
80
79
|
|
|
81
|
-
return this.db
|
|
82
|
-
.pool()
|
|
83
|
-
.query(sql)
|
|
84
|
-
.stream()
|
|
85
|
-
.pipe(
|
|
86
|
-
new Transform({
|
|
87
|
-
objectMode: true,
|
|
88
|
-
transform(row, _, cb) {
|
|
89
|
-
cb(null, row.id)
|
|
90
|
-
},
|
|
91
|
-
}),
|
|
92
|
-
)
|
|
80
|
+
return (this.db.pool().query(sql).stream() as ReadableTyped<ObjectWithId>).map(row => row.id)
|
|
93
81
|
}
|
|
94
82
|
|
|
95
83
|
streamValues(table: string, limit?: number): ReadableTyped<Buffer> {
|
|
@@ -97,18 +85,7 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
|
|
|
97
85
|
if (limit) sql += ` LIMIT ${limit}`
|
|
98
86
|
if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
|
|
99
87
|
|
|
100
|
-
return this.db
|
|
101
|
-
.pool()
|
|
102
|
-
.query(sql)
|
|
103
|
-
.stream()
|
|
104
|
-
.pipe(
|
|
105
|
-
new Transform({
|
|
106
|
-
objectMode: true,
|
|
107
|
-
transform(row, _, cb) {
|
|
108
|
-
cb(null, row.v)
|
|
109
|
-
},
|
|
110
|
-
}),
|
|
111
|
-
)
|
|
88
|
+
return (this.db.pool().query(sql).stream() as ReadableTyped<{ v: Buffer }>).map(row => row.v)
|
|
112
89
|
}
|
|
113
90
|
|
|
114
91
|
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
|
|
@@ -116,18 +93,10 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
|
|
|
116
93
|
if (limit) sql += ` LIMIT ${limit}`
|
|
117
94
|
if (this.cfg.logSQL) this.db.cfg.logger.log(`stream: ${sql}`)
|
|
118
95
|
|
|
119
|
-
return this.db
|
|
120
|
-
.
|
|
121
|
-
.
|
|
122
|
-
|
|
123
|
-
.pipe(
|
|
124
|
-
new Transform({
|
|
125
|
-
objectMode: true,
|
|
126
|
-
transform(row, _, cb) {
|
|
127
|
-
cb(null, [row.id, row.v])
|
|
128
|
-
},
|
|
129
|
-
}),
|
|
130
|
-
)
|
|
96
|
+
return (this.db.pool().query(sql).stream() as ReadableTyped<KeyValueObject>).map(row => [
|
|
97
|
+
row.id,
|
|
98
|
+
row.v,
|
|
99
|
+
])
|
|
131
100
|
}
|
|
132
101
|
|
|
133
102
|
async beginTransaction(): Promise<void> {
|