@itrocks/mysql-maintainer 0.0.18 → 0.1.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.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Contextual = void 0;
4
4
  const mariadb_1 = require("mariadb");
5
5
  const mysql_maintainer_1 = require("./mysql-maintainer");
6
+ const mysql_maintainer_2 = require("./mysql-maintainer");
6
7
  const MANAGED_ERROR_CODES = ['ER_BAD_FIELD_ERROR', 'ER_CANNOT_ADD_FOREIGN', 'ER_NO_SUCH_TABLE'];
7
8
  class Contextual {
8
9
  contexts = [];
@@ -15,16 +16,20 @@ class Contextual {
15
16
  }
16
17
  async query(sql, values) {
17
18
  try {
19
+ if (mysql_maintainer_1.DEBUG)
20
+ console.log(sql, values);
18
21
  return await this.superQuery(sql, values);
19
22
  }
20
23
  catch (error) {
21
24
  if (!(error instanceof mariadb_1.SqlError)
22
25
  || !error.code
23
26
  || !MANAGED_ERROR_CODES.includes(error.code)) {
27
+ if (mysql_maintainer_1.DEBUG)
28
+ console.log('MAINTAINER: throw', error);
24
29
  throw error;
25
30
  }
26
31
  // @ts-ignore query applies to a Connection
27
- if (await new mysql_maintainer_1.MysqlMaintainer(this).manageError(error, this.contexts[this.contexts.length - 1], sql, values)) {
32
+ if (await new mysql_maintainer_2.MysqlMaintainer(this).manageError(error, this.contexts[this.contexts.length - 1], sql, values)) {
28
33
  return this.query(sql, values);
29
34
  }
30
35
  throw error;
@@ -5,6 +5,7 @@ import { QueryOptions } from 'mariadb';
5
5
  import { SqlError } from 'mariadb';
6
6
  import { Context } from './contextual-connection';
7
7
  export { Mysql } from './mysql';
8
+ export declare const DEBUG = false;
8
9
  export declare class MysqlMaintainer {
9
10
  connection: Connection;
10
11
  constructor(connection: Connection);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MysqlMaintainer = exports.Mysql = void 0;
3
+ exports.MysqlMaintainer = exports.DEBUG = exports.Mysql = void 0;
4
4
  const class_type_1 = require("@itrocks/class-type");
5
5
  const mysql_1 = require("@itrocks/mysql");
6
6
  const mysql_to_schema_1 = require("@itrocks/mysql-to-schema");
@@ -11,6 +11,7 @@ const schema_to_mysql_1 = require("@itrocks/schema-to-mysql");
11
11
  const store_1 = require("@itrocks/store");
12
12
  var mysql_2 = require("./mysql");
13
13
  Object.defineProperty(exports, "Mysql", { enumerable: true, get: function () { return mysql_2.Mysql; } });
14
+ exports.DEBUG = false;
14
15
  const DELETION = false;
15
16
  class MysqlMaintainer {
16
17
  connection;
@@ -51,6 +52,8 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
51
52
  return (0, mysql_1.joinTableName)(table1, table2);
52
53
  }
53
54
  async manageError(error, context, sql, values) {
55
+ if (exports.DEBUG)
56
+ console.log('MAINTAINER: manageError', error);
54
57
  switch (error.code) {
55
58
  case 'ER_BAD_FIELD_ERROR':
56
59
  case 'ER_CANNOT_ADD_FOREIGN':
package/cjs/mysql.js CHANGED
@@ -43,14 +43,16 @@ class Mysql extends mysql_1.Mysql {
43
43
  contexts.pop();
44
44
  return result;
45
45
  }
46
- async readCollection(object, property, type = new reflect_1.ReflectProperty(object, property).collectionType.elementType.type) {
46
+ async readCollection(object, property, type) {
47
+ type ??= new reflect_1.ReflectProperty(object, property).collectionType.elementType.type;
47
48
  const contexts = (this.connection ?? await this.connect()).contexts;
48
49
  contexts.push([object, type]);
49
50
  const result = await super.readCollection(object, property, type);
50
51
  contexts.pop();
51
52
  return result;
52
53
  }
53
- async readCollectionIds(object, property, type = new reflect_1.ReflectProperty(object, property).collectionType.elementType.type) {
54
+ async readCollectionIds(object, property, type) {
55
+ type ??= new reflect_1.ReflectProperty(object, property).collectionType.elementType.type;
54
56
  const contexts = (this.connection ?? await this.connect()).contexts;
55
57
  contexts.push([object, type]);
56
58
  const result = await super.readCollectionIds(object, property, type);
@@ -1,4 +1,5 @@
1
1
  import { SqlError } from 'mariadb';
2
+ import { DEBUG } from './mysql-maintainer';
2
3
  import { MysqlMaintainer } from './mysql-maintainer';
3
4
  const MANAGED_ERROR_CODES = ['ER_BAD_FIELD_ERROR', 'ER_CANNOT_ADD_FOREIGN', 'ER_NO_SUCH_TABLE'];
4
5
  export class Contextual {
@@ -12,12 +13,16 @@ export class Contextual {
12
13
  }
13
14
  async query(sql, values) {
14
15
  try {
16
+ if (DEBUG)
17
+ console.log(sql, values);
15
18
  return await this.superQuery(sql, values);
16
19
  }
17
20
  catch (error) {
18
21
  if (!(error instanceof SqlError)
19
22
  || !error.code
20
23
  || !MANAGED_ERROR_CODES.includes(error.code)) {
24
+ if (DEBUG)
25
+ console.log('MAINTAINER: throw', error);
21
26
  throw error;
22
27
  }
23
28
  // @ts-ignore query applies to a Connection
@@ -5,6 +5,7 @@ import { QueryOptions } from 'mariadb';
5
5
  import { SqlError } from 'mariadb';
6
6
  import { Context } from './contextual-connection';
7
7
  export { Mysql } from './mysql';
8
+ export declare const DEBUG = false;
8
9
  export declare class MysqlMaintainer {
9
10
  connection: Connection;
10
11
  constructor(connection: Connection);
@@ -7,6 +7,7 @@ import { SchemaDiffMysql } from '@itrocks/schema-diff-mysql';
7
7
  import { SchemaToMysql } from '@itrocks/schema-to-mysql';
8
8
  import { storeOf } from '@itrocks/store';
9
9
  export { Mysql } from './mysql';
10
+ export const DEBUG = false;
10
11
  const DELETION = false;
11
12
  export class MysqlMaintainer {
12
13
  connection;
@@ -47,6 +48,8 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
47
48
  return joinTableName(table1, table2);
48
49
  }
49
50
  async manageError(error, context, sql, values) {
51
+ if (DEBUG)
52
+ console.log('MAINTAINER: manageError', error);
50
53
  switch (error.code) {
51
54
  case 'ER_BAD_FIELD_ERROR':
52
55
  case 'ER_CANNOT_ADD_FOREIGN':
package/esm/mysql.js CHANGED
@@ -40,14 +40,16 @@ export class Mysql extends M {
40
40
  contexts.pop();
41
41
  return result;
42
42
  }
43
- async readCollection(object, property, type = new ReflectProperty(object, property).collectionType.elementType.type) {
43
+ async readCollection(object, property, type) {
44
+ type ??= new ReflectProperty(object, property).collectionType.elementType.type;
44
45
  const contexts = (this.connection ?? await this.connect()).contexts;
45
46
  contexts.push([object, type]);
46
47
  const result = await super.readCollection(object, property, type);
47
48
  contexts.pop();
48
49
  return result;
49
50
  }
50
- async readCollectionIds(object, property, type = new ReflectProperty(object, property).collectionType.elementType.type) {
51
+ async readCollectionIds(object, property, type) {
52
+ type ??= new ReflectProperty(object, property).collectionType.elementType.type;
51
53
  const contexts = (this.connection ?? await this.connect()).contexts;
52
54
  contexts.push([object, type]);
53
55
  const result = await super.readCollectionIds(object, property, type);
package/package.json CHANGED
@@ -57,5 +57,5 @@
57
57
  "build:esm": "tsc -p tsconfig.esm.json"
58
58
  },
59
59
  "types": "./esm/mysql-maintainer.d.ts",
60
- "version": "0.0.18"
60
+ "version": "0.1.1"
61
61
  }