@itrocks/mysql-maintainer 0.0.12 → 0.0.14
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/cjs/mysql-maintainer.js +6 -9
- package/cjs/mysql.d.ts +2 -1
- package/cjs/mysql.js +2 -2
- package/esm/mysql-maintainer.js +6 -9
- package/esm/mysql.d.ts +2 -1
- package/esm/mysql.js +2 -2
- package/package.json +1 -1
package/cjs/mysql-maintainer.js
CHANGED
|
@@ -24,6 +24,7 @@ const schema_diff_mysql_1 = require("@itrocks/schema-diff-mysql");
|
|
|
24
24
|
const schema_to_mysql_1 = require("@itrocks/schema-to-mysql");
|
|
25
25
|
const store_1 = require("@itrocks/store");
|
|
26
26
|
__exportStar(require("./mysql"), exports);
|
|
27
|
+
const DELETION = false;
|
|
27
28
|
class MysqlMaintainer {
|
|
28
29
|
connection;
|
|
29
30
|
constructor(connection) {
|
|
@@ -54,14 +55,10 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
54
55
|
const tableSchema = new reflect_to_schema_1.ReflectToTable().convert(type);
|
|
55
56
|
const schemaToMysql = new schema_to_mysql_1.SchemaToMysql();
|
|
56
57
|
const sql = schemaToMysql.sql(tableSchema);
|
|
57
|
-
console.log(sql);
|
|
58
58
|
await this.connection.query(sql);
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
async manageError(error, context, sql, values) {
|
|
62
|
-
console.log('query', sql, values);
|
|
63
|
-
console.log('throw', error);
|
|
64
|
-
console.log('context', context);
|
|
65
62
|
switch (error.code) {
|
|
66
63
|
case 'ER_BAD_FIELD_ERROR':
|
|
67
64
|
case 'ER_CANNOT_ADD_FOREIGN':
|
|
@@ -96,14 +93,14 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
96
93
|
new mysql_to_schema_1.MysqlToTable(this.connection).normalize(classTable);
|
|
97
94
|
const mysqlTable = await ((new mysql_to_schema_1.MysqlToTable(this.connection)).convert(tableName));
|
|
98
95
|
const schemaDiff = new schema_diff_1.TableDiff(mysqlTable, classTable);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
if (!schemaDiff.additions.length
|
|
97
|
+
&& !schemaDiff.changes.length
|
|
98
|
+
&& (!schemaDiff.deletions.length || !DELETION)
|
|
99
|
+
&& !schemaDiff.tableChanges()) {
|
|
103
100
|
return false;
|
|
104
101
|
}
|
|
105
102
|
const schemaDiffMysql = new schema_diff_mysql_1.SchemaDiffMysql();
|
|
106
|
-
const sql = schemaDiffMysql.sql(schemaDiff);
|
|
103
|
+
const sql = schemaDiffMysql.sql(schemaDiff, DELETION);
|
|
107
104
|
await this.connection.query(sql);
|
|
108
105
|
return true;
|
|
109
106
|
}
|
package/cjs/mysql.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeyOf } from '@itrocks/class-type';
|
|
2
2
|
import { ObjectOrType } from '@itrocks/class-type';
|
|
3
3
|
import { Type } from '@itrocks/class-type';
|
|
4
|
+
import { Options } from '@itrocks/storage';
|
|
4
5
|
import { Mysql as M } from '@itrocks/mysql';
|
|
5
6
|
import { Entity } from '@itrocks/storage';
|
|
6
7
|
import { Identifier } from '@itrocks/storage';
|
|
@@ -19,6 +20,6 @@ export declare class Mysql extends M {
|
|
|
19
20
|
}>[]>;
|
|
20
21
|
readCollectionIds<T extends object, PT extends object>(object: Entity<T>, property: KeyOf<T>, type?: Type<PT>): Promise<Identifier[]>;
|
|
21
22
|
readMultiple<T extends object>(type: Type<T>, ids: Identifier[]): Promise<Entity<T>[]>;
|
|
22
|
-
search<T extends object>(type: Type<T>, search?: SearchType<T
|
|
23
|
+
search<T extends object>(type: Type<T>, search?: SearchType<T>, options?: Options): Promise<Entity<T>[]>;
|
|
23
24
|
update<T extends object>(object: Entity<T>): Promise<Entity<T>>;
|
|
24
25
|
}
|
package/cjs/mysql.js
CHANGED
|
@@ -64,10 +64,10 @@ class Mysql extends mysql_1.Mysql {
|
|
|
64
64
|
contexts.pop();
|
|
65
65
|
return result;
|
|
66
66
|
}
|
|
67
|
-
async search(type, search = {}) {
|
|
67
|
+
async search(type, search = {}, options) {
|
|
68
68
|
const contexts = (this.connection ?? await this.connect()).contexts;
|
|
69
69
|
contexts.push(type);
|
|
70
|
-
const result = await super.search(type, search);
|
|
70
|
+
const result = await super.search(type, search, options);
|
|
71
71
|
contexts.pop();
|
|
72
72
|
return result;
|
|
73
73
|
}
|
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 * from './mysql';
|
|
10
|
+
const DELETION = false;
|
|
10
11
|
export class MysqlMaintainer {
|
|
11
12
|
connection;
|
|
12
13
|
constructor(connection) {
|
|
@@ -37,14 +38,10 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
37
38
|
const tableSchema = new ReflectToTable().convert(type);
|
|
38
39
|
const schemaToMysql = new SchemaToMysql();
|
|
39
40
|
const sql = schemaToMysql.sql(tableSchema);
|
|
40
|
-
console.log(sql);
|
|
41
41
|
await this.connection.query(sql);
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
async manageError(error, context, sql, values) {
|
|
45
|
-
console.log('query', sql, values);
|
|
46
|
-
console.log('throw', error);
|
|
47
|
-
console.log('context', context);
|
|
48
45
|
switch (error.code) {
|
|
49
46
|
case 'ER_BAD_FIELD_ERROR':
|
|
50
47
|
case 'ER_CANNOT_ADD_FOREIGN':
|
|
@@ -79,14 +76,14 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
79
76
|
new MysqlToTable(this.connection).normalize(classTable);
|
|
80
77
|
const mysqlTable = await ((new MysqlToTable(this.connection)).convert(tableName));
|
|
81
78
|
const schemaDiff = new TableDiff(mysqlTable, classTable);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
if (!schemaDiff.additions.length
|
|
80
|
+
&& !schemaDiff.changes.length
|
|
81
|
+
&& (!schemaDiff.deletions.length || !DELETION)
|
|
82
|
+
&& !schemaDiff.tableChanges()) {
|
|
86
83
|
return false;
|
|
87
84
|
}
|
|
88
85
|
const schemaDiffMysql = new SchemaDiffMysql();
|
|
89
|
-
const sql = schemaDiffMysql.sql(schemaDiff);
|
|
86
|
+
const sql = schemaDiffMysql.sql(schemaDiff, DELETION);
|
|
90
87
|
await this.connection.query(sql);
|
|
91
88
|
return true;
|
|
92
89
|
}
|
package/esm/mysql.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeyOf } from '@itrocks/class-type';
|
|
2
2
|
import { ObjectOrType } from '@itrocks/class-type';
|
|
3
3
|
import { Type } from '@itrocks/class-type';
|
|
4
|
+
import { Options } from '@itrocks/storage';
|
|
4
5
|
import { Mysql as M } from '@itrocks/mysql';
|
|
5
6
|
import { Entity } from '@itrocks/storage';
|
|
6
7
|
import { Identifier } from '@itrocks/storage';
|
|
@@ -19,6 +20,6 @@ export declare class Mysql extends M {
|
|
|
19
20
|
}>[]>;
|
|
20
21
|
readCollectionIds<T extends object, PT extends object>(object: Entity<T>, property: KeyOf<T>, type?: Type<PT>): Promise<Identifier[]>;
|
|
21
22
|
readMultiple<T extends object>(type: Type<T>, ids: Identifier[]): Promise<Entity<T>[]>;
|
|
22
|
-
search<T extends object>(type: Type<T>, search?: SearchType<T
|
|
23
|
+
search<T extends object>(type: Type<T>, search?: SearchType<T>, options?: Options): Promise<Entity<T>[]>;
|
|
23
24
|
update<T extends object>(object: Entity<T>): Promise<Entity<T>>;
|
|
24
25
|
}
|
package/esm/mysql.js
CHANGED
|
@@ -61,10 +61,10 @@ export class Mysql extends M {
|
|
|
61
61
|
contexts.pop();
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
|
-
async search(type, search = {}) {
|
|
64
|
+
async search(type, search = {}, options) {
|
|
65
65
|
const contexts = (this.connection ?? await this.connect()).contexts;
|
|
66
66
|
contexts.push(type);
|
|
67
|
-
const result = await super.search(type, search);
|
|
67
|
+
const result = await super.search(type, search, options);
|
|
68
68
|
contexts.pop();
|
|
69
69
|
return result;
|
|
70
70
|
}
|
package/package.json
CHANGED