@naturalcycles/mysql-lib 3.14.3 → 3.14.5

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/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { getDBAdapter } from './dbAdapter';
2
- import { MysqlDB, MysqlDBCfg, MysqlDBOptions, MysqlDBSaveOptions } from './mysql.db';
3
- import { MySQLKeyValueDB } from './mysqlKeyValueDB';
4
- import { jsonSchemaToMySQLDDL } from './schema/mysql.schema.util';
5
- export type { MysqlDBCfg, MysqlDBOptions, MysqlDBSaveOptions };
6
- export { MysqlDB, MySQLKeyValueDB, jsonSchemaToMySQLDDL, getDBAdapter };
1
+ export * from './mysql.db';
2
+ export * from './mysqlKeyValueDB';
3
+ export { jsonSchemaToMySQLDDL } from './schema/mysql.schema.util';
package/dist/index.js CHANGED
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDBAdapter = exports.jsonSchemaToMySQLDDL = exports.MySQLKeyValueDB = exports.MysqlDB = void 0;
4
- const dbAdapter_1 = require("./dbAdapter");
5
- Object.defineProperty(exports, "getDBAdapter", { enumerable: true, get: function () { return dbAdapter_1.getDBAdapter; } });
6
- const mysql_db_1 = require("./mysql.db");
7
- Object.defineProperty(exports, "MysqlDB", { enumerable: true, get: function () { return mysql_db_1.MysqlDB; } });
8
- const mysqlKeyValueDB_1 = require("./mysqlKeyValueDB");
9
- Object.defineProperty(exports, "MySQLKeyValueDB", { enumerable: true, get: function () { return mysqlKeyValueDB_1.MySQLKeyValueDB; } });
10
- const mysql_schema_util_1 = require("./schema/mysql.schema.util");
3
+ exports.jsonSchemaToMySQLDDL = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./mysql.db"), exports);
6
+ tslib_1.__exportStar(require("./mysqlKeyValueDB"), exports);
7
+ var mysql_schema_util_1 = require("./schema/mysql.schema.util");
11
8
  Object.defineProperty(exports, "jsonSchemaToMySQLDDL", { enumerable: true, get: function () { return mysql_schema_util_1.jsonSchemaToMySQLDDL; } });
@@ -1,5 +1,4 @@
1
- import { DBPatch } from '@naturalcycles/db-lib';
2
- import { BaseCommonDB, CommonDB, CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBQuery, RunQueryResult } from '@naturalcycles/db-lib';
1
+ import { DBPatch, BaseCommonDB, CommonDB, CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBQuery, RunQueryResult, CommonDBSupport, CommonDBType } from '@naturalcycles/db-lib';
3
2
  import { AnyObjectWithId, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
4
3
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
5
4
  import { Connection, Pool, PoolConfig, PoolConnection, QueryOptions } from 'mysql';
@@ -25,6 +24,8 @@ export interface MysqlDBCfg extends PoolConfig {
25
24
  logger?: CommonLogger;
26
25
  }
27
26
  export declare class MysqlDB extends BaseCommonDB implements CommonDB {
27
+ dbType: CommonDBType;
28
+ support: CommonDBSupport;
28
29
  constructor(cfg?: MysqlDBCfg);
29
30
  cfg: MysqlDBCfg & {
30
31
  logger: CommonLogger;
package/dist/mysql.db.js CHANGED
@@ -7,7 +7,7 @@ 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 nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
10
- const mysql = require("mysql");
10
+ const mysql = tslib_1.__importStar(require("mysql"));
11
11
  const query_util_1 = require("./query.util");
12
12
  const mysql_schema_util_1 = require("./schema/mysql.schema.util");
13
13
  const BOOLEAN_TYPES = new Set(['TINY', 'TINYINT', 'INT']);
@@ -34,6 +34,12 @@ const typeCast = (field, next) => {
34
34
  class MysqlDB extends db_lib_1.BaseCommonDB {
35
35
  constructor(cfg = {}) {
36
36
  super();
37
+ this.dbType = db_lib_1.CommonDBType.relational;
38
+ this.support = {
39
+ ...db_lib_1.commonDBFullSupport,
40
+ updateSaveMethod: false,
41
+ transactions: false,
42
+ };
37
43
  this.cfg = {
38
44
  typeCast,
39
45
  // charset: 'utf8mb4', // for emoji support
@@ -205,7 +211,7 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
205
211
  const sql = (0, query_util_1.insertSQL)(table, [row], 'INSERT', this.cfg.logger)[0];
206
212
  const { insertId } = await this.runSQL({ sql });
207
213
  // Mutate the input row with insertIt
208
- rowsInput[i].id = insertId;
214
+ rowsInput[i].id = insertId; // this is because we no longer support number ids in CommonDB
209
215
  }
210
216
  }
211
217
  return;
@@ -1,9 +1,10 @@
1
1
  "use strict";
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
+ const tslib_1 = require("tslib");
4
5
  const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
- const mysql = require("mysql");
7
+ const mysql = tslib_1.__importStar(require("mysql"));
7
8
  const mysql_schema_util_1 = require("./schema/mysql.schema.util");
8
9
  const MAX_PACKET_SIZE = 1024 * 1024; // 1Mb
9
10
  const MAX_ROW_SIZE = 800 * 1024; // 1Mb - margin
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapNameFromMySQL = exports.mapNameToMySQL = exports.mysqlTableStatsToJsonSchemaField = exports.jsonSchemaToMySQLDDL = void 0;
4
- const mysql = require("mysql");
4
+ const tslib_1 = require("tslib");
5
+ const mysql = tslib_1.__importStar(require("mysql"));
5
6
  /**
6
7
  * It currently skips nullability and declares everything as "DEFAULT NULL".
7
8
  */
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "prepare": "husky install"
5
5
  },
6
6
  "dependencies": {
7
- "@naturalcycles/db-lib": "^8.16.2",
7
+ "@naturalcycles/db-lib": "^9.1.0",
8
8
  "@naturalcycles/js-lib": "^14.47.0",
9
9
  "@naturalcycles/nodejs-lib": "^13.1.0",
10
10
  "@types/mysql": "^2.15.19",
@@ -36,7 +36,7 @@
36
36
  "engines": {
37
37
  "node": ">=16.15.0"
38
38
  },
39
- "version": "3.14.3",
39
+ "version": "3.14.5",
40
40
  "description": "MySQL client implementing CommonDB interface",
41
41
  "keywords": [
42
42
  "mysql",
package/src/index.ts CHANGED
@@ -1,8 +1,3 @@
1
- import { getDBAdapter } from './dbAdapter'
2
- import { MysqlDB, MysqlDBCfg, MysqlDBOptions, MysqlDBSaveOptions } from './mysql.db'
3
- import { MySQLKeyValueDB } from './mysqlKeyValueDB'
4
- import { jsonSchemaToMySQLDDL } from './schema/mysql.schema.util'
5
-
6
- export type { MysqlDBCfg, MysqlDBOptions, MysqlDBSaveOptions }
7
-
8
- export { MysqlDB, MySQLKeyValueDB, jsonSchemaToMySQLDDL, getDBAdapter }
1
+ export * from './mysql.db'
2
+ export * from './mysqlKeyValueDB'
3
+ export { jsonSchemaToMySQLDDL } from './schema/mysql.schema.util'
package/src/mysql.db.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Readable, Transform } from 'node:stream'
2
2
  import { promisify } from 'node:util'
3
- import { DBPatch } from '@naturalcycles/db-lib'
4
3
  import {
4
+ DBPatch,
5
5
  BaseCommonDB,
6
6
  CommonDB,
7
7
  CommonDBCreateOptions,
@@ -9,6 +9,9 @@ import {
9
9
  CommonDBSaveOptions,
10
10
  DBQuery,
11
11
  RunQueryResult,
12
+ CommonDBSupport,
13
+ commonDBFullSupport,
14
+ CommonDBType,
12
15
  } from '@naturalcycles/db-lib'
13
16
  import {
14
17
  _assert,
@@ -24,8 +27,7 @@ import {
24
27
  JsonSchemaRootObject,
25
28
  ObjectWithId,
26
29
  } from '@naturalcycles/js-lib'
27
- import { ReadableTyped } from '@naturalcycles/nodejs-lib'
28
- import { white } from '@naturalcycles/nodejs-lib'
30
+ import { ReadableTyped, white } from '@naturalcycles/nodejs-lib'
29
31
  import {
30
32
  Connection,
31
33
  OkPacket,
@@ -92,6 +94,14 @@ const typeCast: TypeCast = (field, next) => {
92
94
  }
93
95
 
94
96
  export class MysqlDB extends BaseCommonDB implements CommonDB {
97
+ override dbType = CommonDBType.relational
98
+
99
+ override support: CommonDBSupport = {
100
+ ...commonDBFullSupport,
101
+ updateSaveMethod: false,
102
+ transactions: false,
103
+ }
104
+
95
105
  constructor(cfg: MysqlDBCfg = {}) {
96
106
  super()
97
107
  this.cfg = {
@@ -322,7 +332,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
322
332
  const { insertId } = await this.runSQL<OkPacket>({ sql })
323
333
 
324
334
  // Mutate the input row with insertIt
325
- rowsInput[i]!.id = insertId
335
+ rowsInput[i]!.id = insertId as any // this is because we no longer support number ids in CommonDB
326
336
  }
327
337
  }
328
338
 
@@ -353,7 +363,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
353
363
  /**
354
364
  * Limitation: always returns [], regardless of which rows are actually deleted
355
365
  */
356
- async deleteByIds<ROW extends ObjectWithId>(
366
+ override async deleteByIds<ROW extends ObjectWithId>(
357
367
  table: string,
358
368
  ids: ROW['id'][],
359
369
  _opt?: MysqlDBOptions,
@@ -1,2 +0,0 @@
1
- import { MysqlDB } from './mysql.db';
2
- export declare function getDBAdapter(cfgStr?: string): MysqlDB;
package/dist/dbAdapter.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDBAdapter = void 0;
4
- const mysql_db_1 = require("./mysql.db");
5
- function getDBAdapter(cfgStr = '{}') {
6
- const cfg = JSON.parse(cfgStr);
7
- return new mysql_db_1.MysqlDB(cfg);
8
- }
9
- exports.getDBAdapter = getDBAdapter;
package/src/dbAdapter.ts DELETED
@@ -1,6 +0,0 @@
1
- import { MysqlDB } from './mysql.db'
2
-
3
- export function getDBAdapter(cfgStr: string = '{}'): MysqlDB {
4
- const cfg = JSON.parse(cfgStr)
5
- return new MysqlDB(cfg)
6
- }