@naturalcycles/mysql-lib 3.14.1 → 3.14.2

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
@@ -6,7 +6,7 @@ const node_stream_1 = require("node:stream");
6
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
- const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
9
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
10
10
  const mysql = require("mysql");
11
11
  const query_util_1 = require("./query.util");
12
12
  const mysql_schema_util_1 = require("./schema/mysql.schema.util");
@@ -52,7 +52,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
52
52
  pool() {
53
53
  const pool = mysql.createPool(this.cfg);
54
54
  const { host, database, logger } = this.cfg;
55
- logger.log(`connected to ${(0, colors_1.white)(host + '/' + database)}`);
55
+ logger.log(`connected to ${(0, nodejs_lib_1.white)(host + '/' + database)}`);
56
56
  if (this.cfg.debugConnections) {
57
57
  pool.on('acquire', con => {
58
58
  logger.log(`acquire(${con.threadId})`);
@@ -281,7 +281,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
281
281
  return affectedRows;
282
282
  }
283
283
  }
284
+ exports.MysqlDB = MysqlDB;
284
285
  tslib_1.__decorate([
285
286
  (0, js_lib_1._Memo)()
286
287
  ], MysqlDB.prototype, "pool", null);
287
- exports.MysqlDB = MysqlDB;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dbQueryToSQLUpdate = exports.insertSQLSetSingle = exports.insertSQLSingle = exports.insertSQL = exports.dbQueryToSQLDelete = exports.dbQueryToSQLSelect = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
6
  const mysql = require("mysql");
7
7
  const mysql_schema_util_1 = require("./schema/mysql.schema.util");
8
8
  const MAX_PACKET_SIZE = 1024 * 1024; // 1Mb
@@ -84,7 +84,7 @@ function insertSQL(table, rows, verb = 'INSERT', logger = console) {
84
84
  if (sql) {
85
85
  sqls.push(sql); // last one
86
86
  }
87
- logger.log(`${(0, colors_1.white)(table)} large sql query (${(0, colors_1.yellow)((0, js_lib_1._hb)(full.length))}) was split into ${(0, colors_1.yellow)(sqls.length)} chunks`);
87
+ logger.log(`${(0, nodejs_lib_1.white)(table)} large sql query (${(0, nodejs_lib_1.yellow)((0, js_lib_1._hb)(full.length))}) was split into ${(0, nodejs_lib_1.yellow)(sqls.length)} chunks`);
88
88
  return sqls;
89
89
  // todo: handle "upsert" later
90
90
  }
package/package.json CHANGED
@@ -36,7 +36,7 @@
36
36
  "engines": {
37
37
  "node": ">=16.15.0"
38
38
  },
39
- "version": "3.14.1",
39
+ "version": "3.14.2",
40
40
  "description": "MySQL client implementing CommonDB interface",
41
41
  "keywords": [
42
42
  "mysql",
package/src/mysql.db.ts CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  ObjectWithId,
26
26
  } from '@naturalcycles/js-lib'
27
27
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
28
- import { white } from '@naturalcycles/nodejs-lib/dist/colors'
28
+ import { white } from '@naturalcycles/nodejs-lib'
29
29
  import {
30
30
  Connection,
31
31
  OkPacket,
@@ -193,7 +193,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
193
193
  if (!ids.length) return []
194
194
  const q = new DBQuery<ROW>(table).filterEq('id', ids)
195
195
  const { rows } = await this.runQuery(q, opt)
196
- return rows.map(r => _mapKeys(r, k => mapNameFromMySQL(k)) as any)
196
+ return rows.map(r => _mapKeys(r, k => mapNameFromMySQL(k as string)) as any)
197
197
  }
198
198
 
199
199
  // QUERY
@@ -209,13 +209,13 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
209
209
  }
210
210
 
211
211
  const rows = (await this.runSQL<ROW[]>({ sql })).map(
212
- row => _mapKeys(_filterUndefinedValues(row, true), k => mapNameFromMySQL(k)) as any,
212
+ row => _mapKeys(_filterUndefinedValues(row, true), k => mapNameFromMySQL(k as string)) as any,
213
213
  )
214
214
 
215
215
  // edge case where 0 fields are selected
216
216
  if (q._selectedFieldNames?.length === 0) {
217
217
  return {
218
- rows: rows.map(_ => ({} as any)),
218
+ rows: rows.map(_ => ({}) as any),
219
219
  }
220
220
  }
221
221
 
@@ -293,7 +293,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
293
293
 
294
294
  // Stringify object values
295
295
  const rows = rowsInput.map(row =>
296
- _mapValues(row, (_k, v) => {
296
+ _mapValues<ROW>(row, (_k, v) => {
297
297
  if (v && typeof v === 'object' && !Buffer.isBuffer(v)) {
298
298
  // This is to avoid implicit Date stringification and mismatch: it gets saved as Date, but loaded as String
299
299
  _assert(
package/src/query.util.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
2
2
  import { _hb, CommonLogger } from '@naturalcycles/js-lib'
3
- import { white, yellow } from '@naturalcycles/nodejs-lib/dist/colors'
3
+ import { white, yellow } from '@naturalcycles/nodejs-lib'
4
4
  import { QueryOptions } from 'mysql'
5
5
  import * as mysql from 'mysql'
6
6
  import { mapNameToMySQL } from './schema/mysql.schema.util'