@naturalcycles/mysql-lib 3.14.0 → 3.14.1

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
@@ -210,6 +210,16 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
210
210
  }
211
211
  return;
212
212
  }
213
+ if (opt.saveMethod === 'update') {
214
+ // TODO: This fails if a combination of entities with id and without id are parsed
215
+ for await (const row of rows) {
216
+ // Update already existing
217
+ (0, js_lib_1._assert)(row.id, 'id is required for updating');
218
+ const query = new db_lib_1.DBQuery(table).filterEq('id', row.id);
219
+ await this.updateByQuery(query, (0, js_lib_1._omit)(row, ['id']));
220
+ }
221
+ return;
222
+ }
213
223
  const verb = opt.saveMethod === 'insert' ? 'INSERT' : 'REPLACE';
214
224
  // inserts are split into multiple sentenses to respect the max_packet_size (1Mb usually)
215
225
  const sqls = (0, query_util_1.insertSQL)(table, rows, verb, this.cfg.logger);
@@ -100,10 +100,10 @@ exports.mysqlTableStatsToJsonSchemaField = mysqlTableStatsToJsonSchemaField;
100
100
  * @param name
101
101
  */
102
102
  function mapNameToMySQL(name) {
103
- return name.replace(/\./g, '_dot_');
103
+ return name.replaceAll('.', '_dot_');
104
104
  }
105
105
  exports.mapNameToMySQL = mapNameToMySQL;
106
106
  function mapNameFromMySQL(name) {
107
- return name.replace(/_dot_/g, '.');
107
+ return name.replaceAll('_dot_', '.');
108
108
  }
109
109
  exports.mapNameFromMySQL = mapNameFromMySQL;
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "@naturalcycles/dev-lib": "^13.2.1",
15
- "@types/node": "^18.7.13",
15
+ "@types/node": "^20.2.3",
16
16
  "dotenv": "^16.0.0",
17
17
  "jest": "^29.0.0"
18
18
  },
@@ -36,7 +36,7 @@
36
36
  "engines": {
37
37
  "node": ">=16.15.0"
38
38
  },
39
- "version": "3.14.0",
39
+ "version": "3.14.1",
40
40
  "description": "MySQL client implementing CommonDB interface",
41
41
  "keywords": [
42
42
  "mysql",
package/src/mysql.db.ts CHANGED
@@ -329,8 +329,18 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
329
329
  return
330
330
  }
331
331
 
332
- const verb = opt.saveMethod === 'insert' ? 'INSERT' : 'REPLACE'
332
+ if (opt.saveMethod === 'update') {
333
+ // TODO: This fails if a combination of entities with id and without id are parsed
334
+ for await (const row of rows) {
335
+ // Update already existing
336
+ _assert(row.id, 'id is required for updating')
337
+ const query = new DBQuery(table).filterEq('id', row.id)
338
+ await this.updateByQuery(query, _omit(row, ['id']))
339
+ }
340
+ return
341
+ }
333
342
 
343
+ const verb = opt.saveMethod === 'insert' ? 'INSERT' : 'REPLACE'
334
344
  // inserts are split into multiple sentenses to respect the max_packet_size (1Mb usually)
335
345
  const sqls = insertSQL(table, rows, verb, this.cfg.logger)
336
346
 
@@ -126,9 +126,9 @@ export function mysqlTableStatsToJsonSchemaField<T extends AnyObject = any>(
126
126
  * @param name
127
127
  */
128
128
  export function mapNameToMySQL(name: string): string {
129
- return name.replace(/\./g, '_dot_')
129
+ return name.replaceAll('.', '_dot_')
130
130
  }
131
131
 
132
132
  export function mapNameFromMySQL(name: string): string {
133
- return name.replace(/_dot_/g, '.')
133
+ return name.replaceAll('_dot_', '.')
134
134
  }