@itrocks/mysql-maintainer 0.3.3 → 0.4.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/README.md +1 -0
- package/cjs/mysql-maintainer.js +9 -3
- package/cjs/mysql.d.ts +2 -0
- package/cjs/mysql.js +3 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -68,6 +68,7 @@ composition system's loading rules.
|
|
|
68
68
|
## How it works
|
|
69
69
|
|
|
70
70
|
The package enriches the usual `Mysql` operations with the context required to identify the persistent classes involved.
|
|
71
|
+
Projection, search and count queries retain every root and related type supplied by the MySQL query graph.
|
|
71
72
|
Each connection stores that context with `AsyncLocalStorage`, so concurrent operations on different classes cannot
|
|
72
73
|
overwrite one another's maintenance target.
|
|
73
74
|
It intercepts MySQL errors that indicate a missing or outdated table, column, or foreign key, derives the expected
|
package/cjs/mysql-maintainer.js
CHANGED
|
@@ -75,10 +75,16 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
75
75
|
throw 'No table name for type';
|
|
76
76
|
}
|
|
77
77
|
const exists = (await this.connection.query('SHOW TABLES LIKE ?', tableName));
|
|
78
|
-
result
|
|
78
|
+
result = await (exists.length ? this.updateTable(type) : this.createTable(type)) || result;
|
|
79
79
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
80
|
+
if (tableName) {
|
|
81
|
+
for (let left = 0; left < contexts.length; left++) {
|
|
82
|
+
for (let right = left + 1; right < contexts.length; right++) {
|
|
83
|
+
if (this.implicitTableName(contexts[left], contexts[right]) !== tableName)
|
|
84
|
+
continue;
|
|
85
|
+
result = await this.createImplicitTable(contexts[left], contexts[right]) || result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
return result;
|
|
84
90
|
}
|
package/cjs/mysql.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ObjectOrType } from '@itrocks/class-type';
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
3
|
import { Mysql as M } from '@itrocks/mysql';
|
|
4
|
+
import { SqlQuery } from '@itrocks/sql-build';
|
|
4
5
|
import { Entity } from '@itrocks/storage';
|
|
5
6
|
import { Identifier } from '@itrocks/storage';
|
|
6
7
|
import { Options } from '@itrocks/storage';
|
|
@@ -20,6 +21,7 @@ export declare class Mysql extends M {
|
|
|
20
21
|
insert<T extends object>(object: T): Promise<Entity<T>>;
|
|
21
22
|
insertRelatedId<T extends Entity>(object: T, property: keyof T, id: Identifier): Promise<void>;
|
|
22
23
|
protected maintainUniqueIndexes(type: Type, connection: ContextualConnection): Promise<void>;
|
|
24
|
+
protected querySelection<T extends object>(query: SqlQuery, types: readonly Type[]): Promise<T[]>;
|
|
23
25
|
read<T extends object>(type: Type<T>, id: Identifier): Promise<Entity<T>>;
|
|
24
26
|
readCollection<T extends object, PT extends object>(object: Entity<T>, property: keyof T, type?: Type<PT>): Promise<Awaited<PT & {
|
|
25
27
|
id: Identifier;
|
package/cjs/mysql.js
CHANGED
|
@@ -70,6 +70,9 @@ class Mysql extends mysql_1.Mysql {
|
|
|
70
70
|
});
|
|
71
71
|
await new mysql_maintainer_1.MysqlMaintainer(originalConnection).updateContextTables(type);
|
|
72
72
|
}
|
|
73
|
+
async querySelection(query, types) {
|
|
74
|
+
return this.withContext([...types], () => super.querySelection(query, types));
|
|
75
|
+
}
|
|
73
76
|
async read(type, id) {
|
|
74
77
|
return this.withContext(type, () => super.read(type, id));
|
|
75
78
|
}
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"@itrocks/schema-diff": "latest",
|
|
13
13
|
"@itrocks/schema-diff-mysql": "latest",
|
|
14
14
|
"@itrocks/schema-to-mysql": "latest",
|
|
15
|
+
"@itrocks/sql-build": "latest",
|
|
15
16
|
"@itrocks/storage": "latest",
|
|
16
17
|
"@itrocks/store": "latest",
|
|
17
18
|
"@itrocks/unique": "latest",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@itrocks/class-file": "latest",
|
|
23
24
|
"@itrocks/rename": "latest",
|
|
25
|
+
"@itrocks/sql-join": "latest",
|
|
24
26
|
"@types/node": "^24.10",
|
|
25
27
|
"typescript": "^7.0"
|
|
26
28
|
},
|
|
@@ -58,5 +60,5 @@
|
|
|
58
60
|
"test": "npm run build && node --test \"test/**/*.test.mjs\"",
|
|
59
61
|
"test:integration": "npm run build && node --test \"test/**/*.integration.mjs\""
|
|
60
62
|
},
|
|
61
|
-
"version": "0.
|
|
63
|
+
"version": "0.4.1"
|
|
62
64
|
}
|