@travetto/model-sql 3.0.3 → 3.1.0-rc.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.
- package/package.json +7 -7
- package/src/service.ts +4 -0
- package/src/table-manager.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-sql",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-rc.0",
|
|
4
4
|
"description": "SQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"directory": "module/model-sql"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/config": "^3.0.
|
|
31
|
-
"@travetto/context": "^3.0.
|
|
32
|
-
"@travetto/model": "^3.0.
|
|
33
|
-
"@travetto/model-query": "^3.0.
|
|
30
|
+
"@travetto/config": "^3.1.0-rc.0",
|
|
31
|
+
"@travetto/context": "^3.1.0-rc.0",
|
|
32
|
+
"@travetto/model": "^3.1.0-rc.0",
|
|
33
|
+
"@travetto/model-query": "^3.1.0-rc.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/command": "^3.0.
|
|
37
|
-
"@travetto/test": "^3.0.
|
|
36
|
+
"@travetto/command": "^3.1.0-rc.0",
|
|
37
|
+
"@travetto/test": "^3.1.0-rc.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/command": {
|
package/src/service.ts
CHANGED
|
@@ -121,6 +121,10 @@ export class SQLModelService implements
|
|
|
121
121
|
return this.#dialect.generateId();
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
async exportModel<T extends ModelType>(e: Class<T>): Promise<string> {
|
|
125
|
+
return (await this.#manager.exportTables(e)).join('\n');
|
|
126
|
+
}
|
|
127
|
+
|
|
124
128
|
async changeSchema(cls: Class, change: SchemaChange): Promise<void> {
|
|
125
129
|
await this.#manager.changeSchema(cls, change);
|
|
126
130
|
}
|
package/src/table-manager.ts
CHANGED
|
@@ -27,6 +27,23 @@ export class TableManager {
|
|
|
27
27
|
return this.#dialect.executeSQL<T>(sql);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Create all needed tables for a given class
|
|
32
|
+
*/
|
|
33
|
+
async exportTables(cls: Class): Promise<string[]> {
|
|
34
|
+
const out: string[] = [];
|
|
35
|
+
for (const op of this.#dialect.getCreateAllTablesSQL(cls)) {
|
|
36
|
+
out.push(op);
|
|
37
|
+
}
|
|
38
|
+
const indices = ModelRegistry.get(cls).indices;
|
|
39
|
+
if (indices) {
|
|
40
|
+
for (const op of this.#dialect.getCreateAllIndicesSQL(cls, indices)) {
|
|
41
|
+
out.push(op);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
/**
|
|
31
48
|
* Create all needed tables for a given class
|
|
32
49
|
*/
|