@naturalcycles/mysql-lib 3.12.1 → 3.12.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
|
@@ -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");
|
|
@@ -75,7 +75,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
75
75
|
async close() {
|
|
76
76
|
const pool = this.pool();
|
|
77
77
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
78
|
-
await (0,
|
|
78
|
+
await (0, node_util_1.promisify)(pool.end.bind(pool))();
|
|
79
79
|
this.cfg.logger.log('closed');
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
@@ -83,7 +83,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
83
83
|
*/
|
|
84
84
|
async getConnection() {
|
|
85
85
|
const pool = this.pool();
|
|
86
|
-
return await (0,
|
|
86
|
+
return await (0, node_util_1.promisify)(pool.getConnection.bind(pool))();
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Manually create a single (not pool) connection.
|
|
@@ -91,7 +91,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
91
91
|
*/
|
|
92
92
|
async createSingleConnection() {
|
|
93
93
|
const con = mysql.createConnection(this.cfg);
|
|
94
|
-
await (0,
|
|
94
|
+
await (0, node_util_1.promisify)(con.connect.bind(con))();
|
|
95
95
|
const { threadId } = con;
|
|
96
96
|
if (this.cfg.debugConnections) {
|
|
97
97
|
this.cfg.logger.log(`createSingleConnection(${threadId})`);
|
|
@@ -163,7 +163,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
163
163
|
streamQuery(q, _opt = {}) {
|
|
164
164
|
const sql = (0, query_util_1.dbQueryToSQLSelect)(q);
|
|
165
165
|
if (!sql) {
|
|
166
|
-
return
|
|
166
|
+
return node_stream_1.Readable.from([]);
|
|
167
167
|
}
|
|
168
168
|
if (this.cfg.logSQL)
|
|
169
169
|
this.cfg.logger.log(`stream: ${sql}`);
|
|
@@ -171,7 +171,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
|
|
|
171
171
|
return this.pool()
|
|
172
172
|
.query(sql)
|
|
173
173
|
.stream()
|
|
174
|
-
.pipe(new
|
|
174
|
+
.pipe(new node_stream_1.Transform({
|
|
175
175
|
objectMode: true,
|
|
176
176
|
transform(row, _encoding, cb) {
|
|
177
177
|
cb(null, (0, js_lib_1._filterUndefinedValues)(row, true));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonLogger, JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AnyObject, CommonLogger, JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
2
2
|
export interface MySQLTableStats {
|
|
3
3
|
Field: string;
|
|
4
4
|
Type: string;
|
|
@@ -14,7 +14,7 @@ export interface MySQLSchemaOptions {
|
|
|
14
14
|
* It currently skips nullability and declares everything as "DEFAULT NULL".
|
|
15
15
|
*/
|
|
16
16
|
export declare function jsonSchemaToMySQLDDL(table: string, schema: JsonSchemaObject<any>, opt?: MySQLSchemaOptions): string;
|
|
17
|
-
export declare function mysqlTableStatsToJsonSchemaField<T = any>(table: string, stats: MySQLTableStats[], logger: CommonLogger): JsonSchemaRootObject<T>;
|
|
17
|
+
export declare function mysqlTableStatsToJsonSchemaField<T extends AnyObject = any>(table: string, stats: MySQLTableStats[], logger: CommonLogger): JsonSchemaRootObject<T>;
|
|
18
18
|
/**
|
|
19
19
|
* Because MySQL doesn't support `.` in field names and escapes them as tableName + fieldName.
|
|
20
20
|
*
|
package/package.json
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"mysql": "^2.17.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@naturalcycles/dev-lib": "^
|
|
15
|
-
"@types/node": "^
|
|
14
|
+
"@naturalcycles/dev-lib": "^13.2.1",
|
|
15
|
+
"@types/node": "^18.7.13",
|
|
16
16
|
"dotenv": "^16.0.0",
|
|
17
|
-
"jest": "^
|
|
17
|
+
"jest": "^29.0.0"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=14.15.0"
|
|
38
38
|
},
|
|
39
|
-
"version": "3.12.
|
|
39
|
+
"version": "3.12.3",
|
|
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,
|
|
@@ -325,7 +325,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
|
|
|
325
325
|
/**
|
|
326
326
|
* Limitation: always returns [], regardless of which rows are actually deleted
|
|
327
327
|
*/
|
|
328
|
-
|
|
328
|
+
async deleteByIds<ROW extends ObjectWithId>(
|
|
329
329
|
table: string,
|
|
330
330
|
ids: ROW['id'][],
|
|
331
331
|
_opt?: MysqlDBOptions,
|
package/src/query.util.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DBQuery } from '@naturalcycles/db-lib'
|
|
2
|
-
import { DBQueryFilterOperator } from '@naturalcycles/db-lib/src/query/dbQuery'
|
|
1
|
+
import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
|
|
3
2
|
import { _hb, CommonLogger } from '@naturalcycles/js-lib'
|
|
4
3
|
import { white, yellow } from '@naturalcycles/nodejs-lib/dist/colors'
|
|
5
4
|
import { QueryOptions } from 'mysql'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AnyObject,
|
|
2
3
|
CommonLogger,
|
|
3
4
|
JsonSchemaBoolean,
|
|
4
5
|
JsonSchemaNumber,
|
|
@@ -79,7 +80,7 @@ export function jsonSchemaToMySQLDDL(
|
|
|
79
80
|
return lines.join('\n')
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
export function mysqlTableStatsToJsonSchemaField<T = any>(
|
|
83
|
+
export function mysqlTableStatsToJsonSchemaField<T extends AnyObject = any>(
|
|
83
84
|
table: string,
|
|
84
85
|
stats: MySQLTableStats[],
|
|
85
86
|
logger: CommonLogger,
|
|
@@ -93,7 +94,7 @@ export function mysqlTableStatsToJsonSchemaField<T = any>(
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
stats.forEach(stat => {
|
|
96
|
-
const name = stat.Field
|
|
97
|
+
const name = stat.Field as keyof T
|
|
97
98
|
const t = stat.Type.toLowerCase()
|
|
98
99
|
const notNull = stat.Null?.toUpperCase() !== 'YES'
|
|
99
100
|
if (notNull) {
|
|
@@ -112,7 +113,7 @@ export function mysqlTableStatsToJsonSchemaField<T = any>(
|
|
|
112
113
|
s.properties[name] = { type: 'number' } as JsonSchemaNumber
|
|
113
114
|
} else {
|
|
114
115
|
logger.log(s)
|
|
115
|
-
throw new Error(`Unknown mysql field type ${name} ${stat.Type}`)
|
|
116
|
+
throw new Error(`Unknown mysql field type ${name as string} ${stat.Type}`)
|
|
116
117
|
}
|
|
117
118
|
})
|
|
118
119
|
|