@naturalcycles/mysql-lib 3.12.2 → 3.12.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/dist/mysql.db.js +13 -9
- package/dist/mysqlKeyValueDB.js +4 -4
- package/package.json +2 -2
- package/src/mysql.db.ts +14 -5
- package/src/mysqlKeyValueDB.ts +1 -1
package/dist/mysql.db.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MysqlDB = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const node_stream_1 = require("node:stream");
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
7
7
|
const db_lib_1 = require("@naturalcycles/db-lib");
|
|
8
8
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
9
9
|
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
@@ -74,8 +74,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
74
74
|
}
|
|
75
75
|
async close() {
|
|
76
76
|
const pool = this.pool();
|
|
77
|
-
|
|
78
|
-
await (0, util_1.promisify)(pool.end.bind(pool))();
|
|
77
|
+
await (0, node_util_1.promisify)(pool.end.bind(pool))();
|
|
79
78
|
this.cfg.logger.log('closed');
|
|
80
79
|
}
|
|
81
80
|
/**
|
|
@@ -83,7 +82,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
83
82
|
*/
|
|
84
83
|
async getConnection() {
|
|
85
84
|
const pool = this.pool();
|
|
86
|
-
return await (0,
|
|
85
|
+
return await (0, node_util_1.promisify)(pool.getConnection.bind(pool))();
|
|
87
86
|
}
|
|
88
87
|
/**
|
|
89
88
|
* Manually create a single (not pool) connection.
|
|
@@ -91,7 +90,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
91
90
|
*/
|
|
92
91
|
async createSingleConnection() {
|
|
93
92
|
const con = mysql.createConnection(this.cfg);
|
|
94
|
-
await (0,
|
|
93
|
+
await (0, node_util_1.promisify)(con.connect.bind(con))();
|
|
95
94
|
const { threadId } = con;
|
|
96
95
|
if (this.cfg.debugConnections) {
|
|
97
96
|
this.cfg.logger.log(`createSingleConnection(${threadId})`);
|
|
@@ -163,7 +162,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
163
162
|
streamQuery(q, _opt = {}) {
|
|
164
163
|
const sql = (0, query_util_1.dbQueryToSQLSelect)(q);
|
|
165
164
|
if (!sql) {
|
|
166
|
-
return
|
|
165
|
+
return node_stream_1.Readable.from([]);
|
|
167
166
|
}
|
|
168
167
|
if (this.cfg.logSQL)
|
|
169
168
|
this.cfg.logger.log(`stream: ${sql}`);
|
|
@@ -171,7 +170,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
171
170
|
return this.pool()
|
|
172
171
|
.query(sql)
|
|
173
172
|
.stream()
|
|
174
|
-
.pipe(new
|
|
173
|
+
.pipe(new node_stream_1.Transform({
|
|
175
174
|
objectMode: true,
|
|
176
175
|
transform(row, _encoding, cb) {
|
|
177
176
|
cb(null, (0, js_lib_1._filterUndefinedValues)(row, true));
|
|
@@ -184,7 +183,12 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
184
183
|
return;
|
|
185
184
|
// Stringify object values
|
|
186
185
|
const rows = rowsInput.map(row => (0, js_lib_1._mapValues)(row, (_k, v) => {
|
|
187
|
-
|
|
186
|
+
if (v && typeof v === 'object' && !Buffer.isBuffer(v)) {
|
|
187
|
+
// This is to avoid implicit Date stringification and mismatch: it gets saved as Date, but loaded as String
|
|
188
|
+
(0, js_lib_1._assert)(!(v instanceof Date), 'mysql-lib does not support Date values, please stringify them before passing');
|
|
189
|
+
return JSON.stringify(v);
|
|
190
|
+
}
|
|
191
|
+
return v;
|
|
188
192
|
}));
|
|
189
193
|
const verb = opt.saveMethod === 'insert' ? 'INSERT' : 'REPLACE';
|
|
190
194
|
if (opt.assignGeneratedIds) {
|
package/dist/mysqlKeyValueDB.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MySQLKeyValueDB = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const mysql_db_1 = require("./mysql.db");
|
|
7
7
|
class MySQLKeyValueDB {
|
|
@@ -67,7 +67,7 @@ class MySQLKeyValueDB {
|
|
|
67
67
|
.pool()
|
|
68
68
|
.query(sql)
|
|
69
69
|
.stream()
|
|
70
|
-
.pipe(new
|
|
70
|
+
.pipe(new node_stream_1.Transform({
|
|
71
71
|
objectMode: true,
|
|
72
72
|
transform(row, _, cb) {
|
|
73
73
|
cb(null, row.id);
|
|
@@ -84,7 +84,7 @@ class MySQLKeyValueDB {
|
|
|
84
84
|
.pool()
|
|
85
85
|
.query(sql)
|
|
86
86
|
.stream()
|
|
87
|
-
.pipe(new
|
|
87
|
+
.pipe(new node_stream_1.Transform({
|
|
88
88
|
objectMode: true,
|
|
89
89
|
transform(row, _, cb) {
|
|
90
90
|
cb(null, row.v);
|
|
@@ -101,7 +101,7 @@ class MySQLKeyValueDB {
|
|
|
101
101
|
.pool()
|
|
102
102
|
.query(sql)
|
|
103
103
|
.stream()
|
|
104
|
-
.pipe(new
|
|
104
|
+
.pipe(new node_stream_1.Transform({
|
|
105
105
|
objectMode: true,
|
|
106
106
|
transform(row, _, cb) {
|
|
107
107
|
cb(null, [row.id, row.v]);
|
package/package.json
CHANGED
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"url": "https://github.com/NaturalCycles/mysql-lib"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
37
|
+
"node": ">=16.15.0"
|
|
38
38
|
},
|
|
39
|
-
"version": "3.12.
|
|
39
|
+
"version": "3.12.4",
|
|
40
40
|
"description": "MySQL client implementing CommonDB interface",
|
|
41
41
|
"keywords": [
|
|
42
42
|
"mysql",
|
package/src/mysql.db.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Readable, Transform } from 'stream'
|
|
2
|
-
import { promisify } from 'util'
|
|
1
|
+
import { Readable, Transform } from 'node:stream'
|
|
2
|
+
import { promisify } from 'node:util'
|
|
3
3
|
import {
|
|
4
4
|
BaseCommonDB,
|
|
5
5
|
CommonDB,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
RunQueryResult,
|
|
11
11
|
} from '@naturalcycles/db-lib'
|
|
12
12
|
import {
|
|
13
|
+
_assert,
|
|
13
14
|
_filterUndefinedValues,
|
|
14
15
|
_mapKeys,
|
|
15
16
|
_mapValues,
|
|
@@ -143,7 +144,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
|
|
|
143
144
|
|
|
144
145
|
async close(): Promise<void> {
|
|
145
146
|
const pool = this.pool()
|
|
146
|
-
|
|
147
|
+
|
|
147
148
|
await promisify(pool.end.bind(pool))()
|
|
148
149
|
this.cfg.logger.log('closed')
|
|
149
150
|
}
|
|
@@ -291,7 +292,15 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
|
|
|
291
292
|
// Stringify object values
|
|
292
293
|
const rows = rowsInput.map(row =>
|
|
293
294
|
_mapValues(row, (_k, v) => {
|
|
294
|
-
|
|
295
|
+
if (v && typeof v === 'object' && !Buffer.isBuffer(v)) {
|
|
296
|
+
// This is to avoid implicit Date stringification and mismatch: it gets saved as Date, but loaded as String
|
|
297
|
+
_assert(
|
|
298
|
+
!(v instanceof Date),
|
|
299
|
+
'mysql-lib does not support Date values, please stringify them before passing',
|
|
300
|
+
)
|
|
301
|
+
return JSON.stringify(v)
|
|
302
|
+
}
|
|
303
|
+
return v
|
|
295
304
|
}),
|
|
296
305
|
)
|
|
297
306
|
|
|
@@ -325,7 +334,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
|
|
|
325
334
|
/**
|
|
326
335
|
* Limitation: always returns [], regardless of which rows are actually deleted
|
|
327
336
|
*/
|
|
328
|
-
|
|
337
|
+
async deleteByIds<ROW extends ObjectWithId>(
|
|
329
338
|
table: string,
|
|
330
339
|
ids: ROW['id'][],
|
|
331
340
|
_opt?: MysqlDBOptions,
|
package/src/mysqlKeyValueDB.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transform } from 'stream'
|
|
1
|
+
import { Transform } from 'node:stream'
|
|
2
2
|
import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib'
|
|
3
3
|
import { pMap } from '@naturalcycles/js-lib'
|
|
4
4
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|