@naturalcycles/mysql-lib 3.14.8 → 3.15.0

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib';
3
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
4
3
  import { MysqlDB, MysqlDBCfg } from './mysql.db';
@@ -22,4 +21,5 @@ export declare class MySQLKeyValueDB implements CommonKeyValueDB {
22
21
  beginTransaction(): Promise<void>;
23
22
  endTransaction(): Promise<void>;
24
23
  count(table: string): Promise<number>;
24
+ increment(_table: string, _id: string, _by?: number): Promise<number>;
25
25
  }
@@ -96,5 +96,8 @@ class MySQLKeyValueDB {
96
96
  const rows = await this.db.runSQL({ sql });
97
97
  return rows[0].cnt;
98
98
  }
99
+ async increment(_table, _id, _by) {
100
+ throw new js_lib_1.AppError('MySQLKeyValueDB.increment() is not implemented');
101
+ }
99
102
  }
100
103
  exports.MySQLKeyValueDB = MySQLKeyValueDB;
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dbQueryToSQLUpdate = exports.insertSQLSetSingle = exports.insertSQLSingle = exports.insertSQL = exports.dbQueryToSQLDelete = exports.dbQueryToSQLSelect = void 0;
3
+ exports.dbQueryToSQLSelect = dbQueryToSQLSelect;
4
+ exports.dbQueryToSQLDelete = dbQueryToSQLDelete;
5
+ exports.insertSQL = insertSQL;
6
+ exports.insertSQLSingle = insertSQLSingle;
7
+ exports.insertSQLSetSingle = insertSQLSetSingle;
8
+ exports.dbQueryToSQLUpdate = dbQueryToSQLUpdate;
4
9
  const tslib_1 = require("tslib");
5
10
  const js_lib_1 = require("@naturalcycles/js-lib");
6
11
  const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
@@ -25,7 +30,6 @@ function dbQueryToSQLSelect(q) {
25
30
  tokens.push(...offsetLimitTokens(q));
26
31
  return tokens.join(' ');
27
32
  }
28
- exports.dbQueryToSQLSelect = dbQueryToSQLSelect;
29
33
  /**
30
34
  * Returns null in "0 rows" case.
31
35
  */
@@ -40,7 +44,6 @@ function dbQueryToSQLDelete(q) {
40
44
  tokens.push(...offsetLimitTokens(q));
41
45
  return tokens.join(' ');
42
46
  }
43
- exports.dbQueryToSQLDelete = dbQueryToSQLDelete;
44
47
  /**
45
48
  * Returns array of sql statements to respect the max sql size.
46
49
  */
@@ -89,7 +92,6 @@ function insertSQL(table, rows, verb = 'INSERT', logger = console) {
89
92
  return sqls;
90
93
  // todo: handle "upsert" later
91
94
  }
92
- exports.insertSQL = insertSQL;
93
95
  function insertSQLSingle(table, record) {
94
96
  // INSERT INTO table_name (column1, column2, column3, ...)
95
97
  // VALUES (value1, value2, value3, ...);
@@ -110,14 +112,12 @@ function insertSQLSingle(table, record) {
110
112
  ];
111
113
  return tokens.join(' ');
112
114
  }
113
- exports.insertSQLSingle = insertSQLSingle;
114
115
  function insertSQLSetSingle(table, record) {
115
116
  return {
116
117
  sql: `INSERT INTO ${mysql.escapeId(table)} SET ?`,
117
118
  values: [record],
118
119
  };
119
120
  }
120
- exports.insertSQLSetSingle = insertSQLSetSingle;
121
121
  function dbQueryToSQLUpdate(q, record) {
122
122
  // var sql = mysql.format('UPDATE posts SET modified = ? WHERE id = ?', [CURRENT_TIMESTAMP, 42]);
123
123
  const whereTokens = getWhereTokens(q);
@@ -134,7 +134,6 @@ function dbQueryToSQLUpdate(q, record) {
134
134
  ];
135
135
  return mysql.format(tokens.join(' '), Object.values(record));
136
136
  }
137
- exports.dbQueryToSQLUpdate = dbQueryToSQLUpdate;
138
137
  function selectTokens(q) {
139
138
  let fields = ['*'];
140
139
  if (q._selectedFieldNames) {
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapNameFromMySQL = exports.mapNameToMySQL = exports.mysqlTableStatsToJsonSchemaField = exports.jsonSchemaToMySQLDDL = void 0;
3
+ exports.jsonSchemaToMySQLDDL = jsonSchemaToMySQLDDL;
4
+ exports.mysqlTableStatsToJsonSchemaField = mysqlTableStatsToJsonSchemaField;
5
+ exports.mapNameToMySQL = mapNameToMySQL;
6
+ exports.mapNameFromMySQL = mapNameFromMySQL;
4
7
  const tslib_1 = require("tslib");
5
8
  const mysql = tslib_1.__importStar(require("mysql"));
6
9
  /**
@@ -56,7 +59,6 @@ function jsonSchemaToMySQLDDL(table, schema, opt = {}) {
56
59
  lines.push(`) ENGINE=${engine}`);
57
60
  return lines.join('\n');
58
61
  }
59
- exports.jsonSchemaToMySQLDDL = jsonSchemaToMySQLDDL;
60
62
  function mysqlTableStatsToJsonSchemaField(table, stats, logger) {
61
63
  const s = {
62
64
  $id: `${table}.schema.json`,
@@ -94,7 +96,6 @@ function mysqlTableStatsToJsonSchemaField(table, stats, logger) {
94
96
  });
95
97
  return s;
96
98
  }
97
- exports.mysqlTableStatsToJsonSchemaField = mysqlTableStatsToJsonSchemaField;
98
99
  /**
99
100
  * Because MySQL doesn't support `.` in field names and escapes them as tableName + fieldName.
100
101
  *
@@ -103,8 +104,6 @@ exports.mysqlTableStatsToJsonSchemaField = mysqlTableStatsToJsonSchemaField;
103
104
  function mapNameToMySQL(name) {
104
105
  return name.replaceAll('.', '_dot_');
105
106
  }
106
- exports.mapNameToMySQL = mapNameToMySQL;
107
107
  function mapNameFromMySQL(name) {
108
108
  return name.replaceAll('_dot_', '.');
109
109
  }
110
- exports.mapNameFromMySQL = mapNameFromMySQL;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "mysql": "^2.17.1"
12
12
  },
13
13
  "devDependencies": {
14
- "@naturalcycles/dev-lib": "^13.2.1",
14
+ "@naturalcycles/dev-lib": "^15.18.0",
15
15
  "@types/node": "^20.2.3",
16
16
  "dotenv": "^16.0.0",
17
17
  "jest": "^29.0.0"
@@ -36,7 +36,7 @@
36
36
  "engines": {
37
37
  "node": ">=18.12.0"
38
38
  },
39
- "version": "3.14.8",
39
+ "version": "3.15.0",
40
40
  "description": "MySQL client implementing CommonDB interface",
41
41
  "keywords": [
42
42
  "mysql",
@@ -1,5 +1,5 @@
1
1
  import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib'
2
- import { ObjectWithId, pMap } from '@naturalcycles/js-lib'
2
+ import { AppError, ObjectWithId, pMap } from '@naturalcycles/js-lib'
3
3
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
4
4
  import { QueryOptions } from 'mysql'
5
5
  import { MysqlDB, MysqlDBCfg } from './mysql.db'
@@ -114,4 +114,8 @@ export class MySQLKeyValueDB implements CommonKeyValueDB {
114
114
  const rows = await this.db.runSQL<{ cnt: number }[]>({ sql })
115
115
  return rows[0]!.cnt
116
116
  }
117
+
118
+ async increment(_table: string, _id: string, _by?: number): Promise<number> {
119
+ throw new AppError('MySQLKeyValueDB.increment() is not implemented')
120
+ }
117
121
  }