@itrocks/mysql-maintainer 0.0.18 → 0.1.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.
|
@@ -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
|
|
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);
|
package/cjs/mysql-maintainer.js
CHANGED
|
@@ -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':
|
|
@@ -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);
|
package/esm/mysql-maintainer.js
CHANGED
|
@@ -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/package.json
CHANGED