db-modeling-markdown 1.0.5 → 2.0.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/CHANGELOG.md +24 -3
- package/CONTRIBUTING.md +78 -0
- package/README.md +63 -46
- package/dist/dialects/core/dbImportProvider.d.ts +5 -0
- package/dist/dialects/core/dbImportProvider.js +7 -0
- package/dist/dialects/core/dbImportProvider.js.map +1 -0
- package/dist/dialects/core/dbProvider.d.ts +19 -6
- package/dist/dialects/core/dbProvider.js +40 -6
- package/dist/dialects/core/dbProvider.js.map +1 -1
- package/dist/dialects/core/dbUtils.d.ts +35 -0
- package/dist/dialects/core/dbUtils.js +159 -0
- package/dist/dialects/core/dbUtils.js.map +1 -0
- package/dist/dialects/core/providerFactory.d.ts +3 -1
- package/dist/dialects/core/providerFactory.js +28 -3
- package/dist/dialects/core/providerFactory.js.map +1 -1
- package/dist/dialects/db2/db2Provider.d.ts +2 -1
- package/dist/dialects/db2/db2Provider.js +75 -46
- package/dist/dialects/db2/db2Provider.js.map +1 -1
- package/dist/dialects/mariadb/mariaDbImportProvider.d.ts +19 -0
- package/dist/dialects/mariadb/mariaDbImportProvider.js +254 -0
- package/dist/dialects/mariadb/mariaDbImportProvider.js.map +1 -0
- package/dist/dialects/mariadb/mariaDbProvider.d.ts +11 -11
- package/dist/dialects/mariadb/mariaDbProvider.js +128 -161
- package/dist/dialects/mariadb/mariaDbProvider.js.map +1 -1
- package/dist/dialects/mariadb/mariaDbUtil.d.ts +6 -0
- package/dist/dialects/mariadb/mariaDbUtil.js +23 -0
- package/dist/dialects/mariadb/mariaDbUtil.js.map +1 -0
- package/dist/dialects/mssql/msSqlProvider.d.ts +2 -1
- package/dist/dialects/mssql/msSqlProvider.js +128 -73
- package/dist/dialects/mssql/msSqlProvider.js.map +1 -1
- package/dist/dialects/mysql/mySqlImportProvider.d.ts +3 -0
- package/dist/dialects/mysql/mySqlImportProvider.js +8 -0
- package/dist/dialects/mysql/mySqlImportProvider.js.map +1 -0
- package/dist/dialects/mysql/mySqlProvider.d.ts +2 -20
- package/dist/dialects/mysql/mySqlProvider.js +2 -182
- package/dist/dialects/mysql/mySqlProvider.js.map +1 -1
- package/dist/dialects/oracle/oracleProvider.d.ts +5 -1
- package/dist/dialects/oracle/oracleProvider.js +111 -70
- package/dist/dialects/oracle/oracleProvider.js.map +1 -1
- package/dist/dialects/postgresql/postgreSqlProvider.d.ts +2 -1
- package/dist/dialects/postgresql/postgreSqlProvider.js +34 -31
- package/dist/dialects/postgresql/postgreSqlProvider.js.map +1 -1
- package/dist/dialects/sqlite/sqliteSqlProvider.d.ts +2 -1
- package/dist/dialects/sqlite/sqliteSqlProvider.js +38 -28
- package/dist/dialects/sqlite/sqliteSqlProvider.js.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/code-flow/codeFlow.js.map +1 -1
- package/dist/lib/markdown-object/markdownModel.d.ts +0 -4
- package/dist/lib/markdown-object/markdownModel.js +0 -4
- package/dist/lib/markdown-object/markdownModel.js.map +1 -1
- package/dist/lib/markdown-object/markdownReader.d.ts +19 -0
- package/dist/lib/markdown-object/markdownReader.js +85 -28
- package/dist/lib/markdown-object/markdownReader.js.map +1 -1
- package/dist/lib/markdown-object/markdownWriter.d.ts +25 -1
- package/dist/lib/markdown-object/markdownWriter.js +117 -52
- package/dist/lib/markdown-object/markdownWriter.js.map +1 -1
- package/dist/lib/markdown-object/readerContext.js +3 -1
- package/dist/lib/markdown-object/readerContext.js.map +1 -1
- package/dist/lib/utils/fileHelper.d.ts +4 -0
- package/dist/lib/utils/fileHelper.js +20 -1
- package/dist/lib/utils/fileHelper.js.map +1 -1
- package/dist/lib/utils/logger.js.map +1 -1
- package/dist/lib/utils/markdownParser.js +3 -6
- package/dist/lib/utils/markdownParser.js.map +1 -1
- package/dist/lib/utils/sqlHelper.js.map +1 -1
- package/dist/lib/utils/textFileReader.js +2 -2
- package/dist/lib/utils/textFileReader.js.map +1 -1
- package/dist/lib/utils/textHelper.d.ts +18 -0
- package/dist/lib/utils/textHelper.js +62 -0
- package/dist/lib/utils/textHelper.js.map +1 -1
- package/dist/{services → models}/databaseTypes.d.ts +0 -0
- package/dist/{services → models}/databaseTypes.js +0 -0
- package/dist/models/databaseTypes.js.map +1 -0
- package/dist/models/dbColumn.d.ts +43 -0
- package/dist/models/dbColumn.js +3 -0
- package/dist/models/dbColumn.js.map +1 -0
- package/dist/models/dbDiffModel.d.ts +43 -0
- package/dist/models/dbDiffModel.js +3 -0
- package/dist/models/dbDiffModel.js.map +1 -0
- package/dist/models/dbForeignKey.d.ts +33 -0
- package/dist/models/dbForeignKey.js +3 -0
- package/dist/models/dbForeignKey.js.map +1 -0
- package/dist/models/dbIndex.d.ts +28 -0
- package/dist/models/dbIndex.js +3 -0
- package/dist/models/dbIndex.js.map +1 -0
- package/dist/models/dbIndexType.d.ts +8 -0
- package/dist/models/dbIndexType.js +13 -0
- package/dist/models/dbIndexType.js.map +1 -0
- package/dist/models/dbModel.d.ts +10 -0
- package/dist/{services → models}/dbModel.js +0 -0
- package/dist/{services → models}/dbModel.js.map +1 -1
- package/dist/models/dbPrimaryKey.d.ts +16 -0
- package/dist/models/dbPrimaryKey.js +3 -0
- package/dist/models/dbPrimaryKey.js.map +1 -0
- package/dist/models/dbTable.d.ts +49 -0
- package/dist/models/dbTable.js +3 -0
- package/dist/models/dbTable.js.map +1 -0
- package/dist/models/dbTableMarkdown.d.ts +34 -0
- package/dist/models/dbTableMarkdown.js +3 -0
- package/dist/models/dbTableMarkdown.js.map +1 -0
- package/dist/services/dbOptions.d.ts +35 -0
- package/dist/services/dbOptions.js +18 -0
- package/dist/services/dbOptions.js.map +1 -0
- package/dist/services/dbmOptions.d.ts +1 -1
- package/dist/services/dbmOptions.js +1 -1
- package/dist/services/dbmOptions.js.map +1 -1
- package/dist/services/dbmService.d.ts +36 -1
- package/dist/services/dbmService.js +80 -13
- package/dist/services/dbmService.js.map +1 -1
- package/package.json +74 -81
- package/.eslintcache +0 -1
- package/.prettierrc +0 -8
- package/dist/services/databaseTypes.js.map +0 -1
- package/dist/services/dbModel.d.ts +0 -135
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describe a table column
|
|
3
|
+
*/
|
|
4
|
+
export interface DbColumn {
|
|
5
|
+
/**
|
|
6
|
+
* The column name before the column (used in upgrading cases)
|
|
7
|
+
*/
|
|
8
|
+
afterColumn?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The character set of the text column
|
|
11
|
+
*/
|
|
12
|
+
characterSet?: string;
|
|
13
|
+
/**
|
|
14
|
+
* the collation of the text column
|
|
15
|
+
*/
|
|
16
|
+
collation?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The column comment
|
|
19
|
+
*/
|
|
20
|
+
comment?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The table default value.
|
|
23
|
+
* <empty> is no default value.
|
|
24
|
+
* Value `''` for default value empty
|
|
25
|
+
*/
|
|
26
|
+
default?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The column label
|
|
29
|
+
*/
|
|
30
|
+
label?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The column name
|
|
33
|
+
*/
|
|
34
|
+
name: string;
|
|
35
|
+
/**
|
|
36
|
+
* If the column nullable
|
|
37
|
+
*/
|
|
38
|
+
nullable?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The column data type
|
|
41
|
+
*/
|
|
42
|
+
type: string;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbColumn.js","sourceRoot":"","sources":["../../src/models/dbColumn.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DbColumn } from './dbColumn';
|
|
2
|
+
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
+
import { DbIndex } from './dbIndex';
|
|
4
|
+
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
+
import { DbTable } from './dbTable';
|
|
6
|
+
/**
|
|
7
|
+
* Describe a database model
|
|
8
|
+
*/
|
|
9
|
+
export interface DbDiffModel {
|
|
10
|
+
/**
|
|
11
|
+
* The model tables
|
|
12
|
+
*/
|
|
13
|
+
diffTables: DbDiffTable[];
|
|
14
|
+
/**
|
|
15
|
+
* new tables
|
|
16
|
+
*/
|
|
17
|
+
newTables: DbTable[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Describe a database diffrent model
|
|
21
|
+
*/
|
|
22
|
+
export interface DbDiffTable {
|
|
23
|
+
/**
|
|
24
|
+
* The table name
|
|
25
|
+
*/
|
|
26
|
+
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* new columns
|
|
29
|
+
*/
|
|
30
|
+
newColumns: DbColumn[];
|
|
31
|
+
/**
|
|
32
|
+
* new foreign keys
|
|
33
|
+
*/
|
|
34
|
+
newForeignKeys: DbForeignKey[];
|
|
35
|
+
/**
|
|
36
|
+
* new Index
|
|
37
|
+
*/
|
|
38
|
+
newIndexes: DbIndex[];
|
|
39
|
+
/**
|
|
40
|
+
* new primary key
|
|
41
|
+
*/
|
|
42
|
+
newPrimaryKeys?: DbPrimaryKey;
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbDiffModel.js","sourceRoot":"","sources":["../../src/models/dbDiffModel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describe the table foreign key
|
|
3
|
+
*/
|
|
4
|
+
export interface DbForeignKey {
|
|
5
|
+
/**
|
|
6
|
+
* The foreign key columns.
|
|
7
|
+
*
|
|
8
|
+
* Use comma `,` to split multiple columns.
|
|
9
|
+
* E.g. `column, column2`
|
|
10
|
+
*/
|
|
11
|
+
columns: string;
|
|
12
|
+
/**
|
|
13
|
+
* The name of the foreign key
|
|
14
|
+
*/
|
|
15
|
+
name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The foreign key options
|
|
18
|
+
*
|
|
19
|
+
* E.g. `ON DELETE CASCADE`
|
|
20
|
+
*/
|
|
21
|
+
options?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The reference columns of the foreign key columns.
|
|
24
|
+
*
|
|
25
|
+
* Use comma `,` to split multiple columns.
|
|
26
|
+
* E.g. `column, column2`
|
|
27
|
+
*/
|
|
28
|
+
refColumns: string;
|
|
29
|
+
/**
|
|
30
|
+
* The reference table of the foreign key
|
|
31
|
+
*/
|
|
32
|
+
refTable: string;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbForeignKey.js","sourceRoot":"","sources":["../../src/models/dbForeignKey.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describe the table index
|
|
3
|
+
*/
|
|
4
|
+
export interface DbIndex {
|
|
5
|
+
/**
|
|
6
|
+
* If the index is clusterred
|
|
7
|
+
*/
|
|
8
|
+
cluster?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The index columns.
|
|
11
|
+
*
|
|
12
|
+
* Use comma `,` to split multiple columns.
|
|
13
|
+
* E.g. `column, column2`
|
|
14
|
+
*/
|
|
15
|
+
columns: string;
|
|
16
|
+
/**
|
|
17
|
+
* The name of the index
|
|
18
|
+
*/
|
|
19
|
+
name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* the index type
|
|
22
|
+
*/
|
|
23
|
+
type?: string;
|
|
24
|
+
/**
|
|
25
|
+
* If the index is unique
|
|
26
|
+
*/
|
|
27
|
+
unique?: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbIndex.js","sourceRoot":"","sources":["../../src/models/dbIndex.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DbIndexType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Describe the table index type
|
|
6
|
+
*/
|
|
7
|
+
var DbIndexType;
|
|
8
|
+
(function (DbIndexType) {
|
|
9
|
+
DbIndexType["FullText"] = "FullText";
|
|
10
|
+
DbIndexType["Index"] = "Index";
|
|
11
|
+
DbIndexType["PrimaryKey"] = "Primary Key";
|
|
12
|
+
})(DbIndexType = exports.DbIndexType || (exports.DbIndexType = {}));
|
|
13
|
+
//# sourceMappingURL=dbIndexType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbIndexType.js","sourceRoot":"","sources":["../../src/models/dbIndexType.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACtB,oCAAqB,CAAA;IACrB,8BAAe,CAAA;IACf,yCAA0B,CAAA;AAC3B,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB"}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbModel.js","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"dbModel.js","sourceRoot":"","sources":["../../src/models/dbModel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describe table primary key
|
|
3
|
+
*/
|
|
4
|
+
export interface DbPrimaryKey {
|
|
5
|
+
/**
|
|
6
|
+
* If the primary key is clusterred
|
|
7
|
+
*/
|
|
8
|
+
cluster?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The primary key columns.
|
|
11
|
+
*
|
|
12
|
+
* Use comma `,` to split multiple columns.
|
|
13
|
+
* E.g. `column, column2`
|
|
14
|
+
*/
|
|
15
|
+
columns: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbPrimaryKey.js","sourceRoot":"","sources":["../../src/models/dbPrimaryKey.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DbColumn } from './dbColumn';
|
|
2
|
+
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
+
import { DbIndex } from './dbIndex';
|
|
4
|
+
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
+
/**
|
|
6
|
+
* Describe a table
|
|
7
|
+
*/
|
|
8
|
+
export interface DbTable {
|
|
9
|
+
/**
|
|
10
|
+
* auto increment start
|
|
11
|
+
*/
|
|
12
|
+
autoIncrement?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The character set of the text column
|
|
15
|
+
*/
|
|
16
|
+
characterSet?: string;
|
|
17
|
+
/**
|
|
18
|
+
* the collation of the text column
|
|
19
|
+
*/
|
|
20
|
+
collation?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The table columns
|
|
23
|
+
*/
|
|
24
|
+
columns: DbColumn[];
|
|
25
|
+
/**
|
|
26
|
+
* The table comment
|
|
27
|
+
*/
|
|
28
|
+
comment?: string;
|
|
29
|
+
/**
|
|
30
|
+
* DB Engin
|
|
31
|
+
*/
|
|
32
|
+
engine?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The table foreign keys
|
|
35
|
+
*/
|
|
36
|
+
foreignKeys: DbForeignKey[];
|
|
37
|
+
/**
|
|
38
|
+
* The table indexes
|
|
39
|
+
*/
|
|
40
|
+
indexes: DbIndex[];
|
|
41
|
+
/**
|
|
42
|
+
* The table name
|
|
43
|
+
*/
|
|
44
|
+
name: string;
|
|
45
|
+
/**
|
|
46
|
+
* The table primary key
|
|
47
|
+
*/
|
|
48
|
+
primaryKey?: DbPrimaryKey;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbTable.js","sourceRoot":"","sources":["../../src/models/dbTable.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DbColumn } from './dbColumn';
|
|
2
|
+
import { DbForeignKey } from './dbForeignKey';
|
|
3
|
+
import { DbIndex } from './dbIndex';
|
|
4
|
+
import { DbPrimaryKey } from './dbPrimaryKey';
|
|
5
|
+
/**
|
|
6
|
+
* Describe a table
|
|
7
|
+
*/
|
|
8
|
+
export interface DbTableMarkdown {
|
|
9
|
+
/**
|
|
10
|
+
* The table columns
|
|
11
|
+
*/
|
|
12
|
+
columns: DbColumn[];
|
|
13
|
+
/**
|
|
14
|
+
* The table foreign keys
|
|
15
|
+
*/
|
|
16
|
+
foreignKeys: DbForeignKey[];
|
|
17
|
+
/**
|
|
18
|
+
* The table indexes
|
|
19
|
+
*/
|
|
20
|
+
indexes: DbIndex[];
|
|
21
|
+
/**
|
|
22
|
+
* The table primary key
|
|
23
|
+
*/
|
|
24
|
+
primaryKey?: DbPrimaryKey[];
|
|
25
|
+
/**
|
|
26
|
+
* The table header
|
|
27
|
+
*/
|
|
28
|
+
table: {
|
|
29
|
+
characterSet?: string;
|
|
30
|
+
collation?: string;
|
|
31
|
+
comment?: string;
|
|
32
|
+
name: string;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbTableMarkdown.js","sourceRoot":"","sources":["../../src/models/dbTableMarkdown.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DatabaseTypes } from '../models/databaseTypes';
|
|
2
|
+
/**
|
|
3
|
+
* Options for database connection
|
|
4
|
+
*/
|
|
5
|
+
export declare class DbOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The database type
|
|
8
|
+
* Default is `mariadb`
|
|
9
|
+
*/
|
|
10
|
+
databaseType: DatabaseTypes;
|
|
11
|
+
/**
|
|
12
|
+
* The database url
|
|
13
|
+
*/
|
|
14
|
+
databaseUrl?: string;
|
|
15
|
+
/**
|
|
16
|
+
* the user name to access database
|
|
17
|
+
*/
|
|
18
|
+
user?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The user password
|
|
21
|
+
*/
|
|
22
|
+
password?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The database port
|
|
25
|
+
*/
|
|
26
|
+
port?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The database host
|
|
29
|
+
*/
|
|
30
|
+
host?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The database name
|
|
33
|
+
*/
|
|
34
|
+
database?: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DbOptions = void 0;
|
|
4
|
+
const databaseTypes_1 = require("../models/databaseTypes");
|
|
5
|
+
/**
|
|
6
|
+
* Options for database connection
|
|
7
|
+
*/
|
|
8
|
+
class DbOptions {
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
* The database type
|
|
12
|
+
* Default is `mariadb`
|
|
13
|
+
*/
|
|
14
|
+
this.databaseType = databaseTypes_1.DatabaseTypes.mariadb;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.DbOptions = DbOptions;
|
|
18
|
+
//# sourceMappingURL=dbOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbOptions.js","sourceRoot":"","sources":["../../src/services/dbOptions.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAEvD;;GAEG;AACH,MAAa,SAAS;IAAtB;QACC;;;WAGG;QACH,iBAAY,GAAkB,6BAAa,CAAC,OAAO,CAAA;IA+BpD,CAAC;CAAA;AApCD,8BAoCC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultOptions = exports.DbmOptions = void 0;
|
|
4
|
-
const databaseTypes_1 = require("
|
|
4
|
+
const databaseTypes_1 = require("../models/databaseTypes");
|
|
5
5
|
/**
|
|
6
6
|
* Options for generation functions
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbmOptions.js","sourceRoot":"","sources":["../../src/services/dbmOptions.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"dbmOptions.js","sourceRoot":"","sources":["../../src/services/dbmOptions.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAEvD;;GAEG;AACH,MAAa,UAAU;IAAvB;QACC;;WAEG;QACH,aAAQ,GAAkB,6BAAa,CAAC,KAAK,CAAA;QAE7C;;;WAGG;QACH,oBAAe,GAAW,QAAQ,CAAA;QAElC;;WAEG;QACH,iBAAY,GAAW,EAAE,CAAA;QAEzB;;WAEG;QACH,eAAU,GAAW,EAAE,CAAA;IACxB,CAAC;CAAA;AArBD,gCAqBC;AAEY,QAAA,cAAc,GAAG,IAAI,UAAU,EAAE,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DbModel } from '
|
|
1
|
+
import { DbModel } from '../models/dbModel';
|
|
2
2
|
import { DbmOptions } from './dbmOptions';
|
|
3
|
+
import { DbOptions } from './dbOptions';
|
|
3
4
|
/**
|
|
4
5
|
* The database modeling markdown service.
|
|
5
6
|
*/
|
|
@@ -31,11 +32,30 @@ export declare class DbmService {
|
|
|
31
32
|
* @param options the options, required: `database`, `sourceFolder`, `targetPath`.
|
|
32
33
|
*/
|
|
33
34
|
static toDropThenCreateTableSql(options: DbmOptions): string;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a SQL file with upgrade scripts.
|
|
37
|
+
* support:
|
|
38
|
+
* - new tables,
|
|
39
|
+
* - new columns,
|
|
40
|
+
* - new primary keys
|
|
41
|
+
* - new indexes
|
|
42
|
+
* - new foreign keys
|
|
43
|
+
* @param options the options, required: `database`, `sourceFolder`, `targetPath`.
|
|
44
|
+
*/
|
|
45
|
+
static toUpgradeSql(fromOptions: DbmOptions, options: DbmOptions): string;
|
|
34
46
|
/**
|
|
35
47
|
* Generate a JSON file.
|
|
36
48
|
* @param options the options, required: `database`, `sourceFolder`, `targetPath`.
|
|
37
49
|
*/
|
|
38
50
|
static toJson(options: DbmOptions): string;
|
|
51
|
+
/**
|
|
52
|
+
* Generate markdown files from a json file
|
|
53
|
+
* @param jsonFile the json file path
|
|
54
|
+
* @param markdownFolder the folder to which we will write
|
|
55
|
+
* @param force If true, delete all files whose extension matched, default: `false`.
|
|
56
|
+
* @param fileExtension generated file extension, default: `.db.md`.
|
|
57
|
+
*/
|
|
58
|
+
static fromJsonFile(jsonFile: string, markdownFolder: string, force?: boolean, fileExtension?: string): void;
|
|
39
59
|
/**
|
|
40
60
|
* Generate markdown files from a model
|
|
41
61
|
* @param model the model object with
|
|
@@ -44,9 +64,24 @@ export declare class DbmService {
|
|
|
44
64
|
* @param fileExtension generated file extension, default: `.db.md`.
|
|
45
65
|
*/
|
|
46
66
|
static toMarkdown(model: DbModel, markdownFolder: string, force?: boolean, fileExtension?: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Generate a index file for a model
|
|
69
|
+
* @param model the model object with
|
|
70
|
+
* @param markdownFolder the folder to which we will write
|
|
71
|
+
* @param filename generated file name, default: `index.md`.
|
|
72
|
+
*/
|
|
73
|
+
static genIndexFile(model: DbModel, markdownFolder: string, filename?: string): void;
|
|
47
74
|
/**
|
|
48
75
|
* Get a model object.
|
|
49
76
|
* @param options the options, required: `database`, `sourceFolder`.
|
|
50
77
|
*/
|
|
51
78
|
static toModel(options: DbmOptions): DbModel;
|
|
79
|
+
/**
|
|
80
|
+
* Generate markdown files from a database
|
|
81
|
+
* @param dbOptions the datbase connection configure
|
|
82
|
+
* @param markdownFolder the folder to which we will write
|
|
83
|
+
* @param force If true, delete all files whose extension matched, default: `false`.
|
|
84
|
+
* @param fileExtension generated file extension, default: `.db.md`.
|
|
85
|
+
*/
|
|
86
|
+
static fromDatabase(dbOptions: DbOptions, markdownFolder: string, force?: boolean, fileExtension?: string): Promise<void>;
|
|
52
87
|
}
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DbmService = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const
|
|
6
|
+
const providerFactory_1 = require("../dialects/core/providerFactory");
|
|
7
7
|
const markdownReader_1 = require("../lib/markdown-object/markdownReader");
|
|
8
8
|
const markdownWriter_1 = require("../lib/markdown-object/markdownWriter");
|
|
9
|
-
const
|
|
9
|
+
const fileHelper_1 = require("../lib/utils/fileHelper");
|
|
10
|
+
const databaseTypes_1 = require("../models/databaseTypes");
|
|
10
11
|
/**
|
|
11
12
|
* The database modeling markdown service.
|
|
12
13
|
*/
|
|
@@ -64,9 +65,8 @@ class DbmService {
|
|
|
64
65
|
],
|
|
65
66
|
};
|
|
66
67
|
const table = model.tables[0];
|
|
67
|
-
|
|
68
|
+
return markdownWriter_1.MarkdownWriter.renderTable(table, options.sourceFolder &&
|
|
68
69
|
path.join(options.sourceFolder, `${table.name}${options.mdFileExtension}`));
|
|
69
|
-
return content;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Generate a SQL file with create-table-if-not-exists scripts.
|
|
@@ -120,6 +120,26 @@ class DbmService {
|
|
|
120
120
|
}
|
|
121
121
|
return sql;
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Generate a SQL file with upgrade scripts.
|
|
125
|
+
* support:
|
|
126
|
+
* - new tables,
|
|
127
|
+
* - new columns,
|
|
128
|
+
* - new primary keys
|
|
129
|
+
* - new indexes
|
|
130
|
+
* - new foreign keys
|
|
131
|
+
* @param options the options, required: `database`, `sourceFolder`, `targetPath`.
|
|
132
|
+
*/
|
|
133
|
+
static toUpgradeSql(fromOptions, options) {
|
|
134
|
+
const fromModel = this.toModel(fromOptions);
|
|
135
|
+
const model = this.toModel(options);
|
|
136
|
+
const provider = providerFactory_1.ProviderFactory.getProvider(options.database);
|
|
137
|
+
const sql = provider.getUpgradeSql(fromModel, model, true);
|
|
138
|
+
if (options.targetPath) {
|
|
139
|
+
fileHelper_1.FileHelper.writeFileSync(options.targetPath, sql);
|
|
140
|
+
}
|
|
141
|
+
return sql;
|
|
142
|
+
}
|
|
123
143
|
/**
|
|
124
144
|
* Generate a JSON file.
|
|
125
145
|
* @param options the options, required: `database`, `sourceFolder`, `targetPath`.
|
|
@@ -131,6 +151,17 @@ class DbmService {
|
|
|
131
151
|
}
|
|
132
152
|
return JSON.stringify(model, null, 2);
|
|
133
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Generate markdown files from a json file
|
|
156
|
+
* @param jsonFile the json file path
|
|
157
|
+
* @param markdownFolder the folder to which we will write
|
|
158
|
+
* @param force If true, delete all files whose extension matched, default: `false`.
|
|
159
|
+
* @param fileExtension generated file extension, default: `.db.md`.
|
|
160
|
+
*/
|
|
161
|
+
static fromJsonFile(jsonFile, markdownFolder, force = false, fileExtension = '.db.md') {
|
|
162
|
+
const model = JSON.parse(fileHelper_1.FileHelper.readJsonFileSync(jsonFile));
|
|
163
|
+
this.toMarkdown(model, markdownFolder, force, fileExtension);
|
|
164
|
+
}
|
|
134
165
|
/**
|
|
135
166
|
* Generate markdown files from a model
|
|
136
167
|
* @param model the model object with
|
|
@@ -139,20 +170,44 @@ class DbmService {
|
|
|
139
170
|
* @param fileExtension generated file extension, default: `.db.md`.
|
|
140
171
|
*/
|
|
141
172
|
static toMarkdown(model, markdownFolder, force = false, fileExtension = '.db.md') {
|
|
142
|
-
if (fs.existsSync(markdownFolder)) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
fs.unlinkSync(path.join(markdownFolder, file.name));
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
173
|
+
if (force && fs.existsSync(markdownFolder)) {
|
|
174
|
+
fileHelper_1.FileHelper.removeAllFilesSync(markdownFolder, fileExtension);
|
|
175
|
+
}
|
|
176
|
+
if (!fs.existsSync(markdownFolder)) {
|
|
177
|
+
fileHelper_1.FileHelper.mkdirSync(markdownFolder);
|
|
151
178
|
}
|
|
152
179
|
model.tables.forEach((table) => {
|
|
153
180
|
markdownWriter_1.MarkdownWriter.renderTable(table, path.join(markdownFolder, `${table.name}${fileExtension}`));
|
|
154
181
|
});
|
|
155
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Generate a index file for a model
|
|
185
|
+
* @param model the model object with
|
|
186
|
+
* @param markdownFolder the folder to which we will write
|
|
187
|
+
* @param filename generated file name, default: `index.md`.
|
|
188
|
+
*/
|
|
189
|
+
static genIndexFile(model, markdownFolder, filename = 'index.md') {
|
|
190
|
+
const file = path.join(markdownFolder, filename);
|
|
191
|
+
fileHelper_1.FileHelper.removeFileSync(file);
|
|
192
|
+
let data = '# Database Design\n\n';
|
|
193
|
+
data += '## Index\n\n';
|
|
194
|
+
const columnWidths = [5, 6];
|
|
195
|
+
model.tables.forEach((table) => {
|
|
196
|
+
if (table.name.length * 2 + 10 > columnWidths[0]) {
|
|
197
|
+
columnWidths[0] = table.name.length * 2 + 10;
|
|
198
|
+
}
|
|
199
|
+
if (table.comment && table.comment.length > columnWidths[1]) {
|
|
200
|
+
columnWidths[1] = table.comment.length;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
data += `| ${'Table'.padEnd(columnWidths[0], ' ')} | ${'Comment'.padEnd(columnWidths[1], ' ')} |\n`;
|
|
204
|
+
data += `| ${''.padEnd(columnWidths[0], '-')} | ${''.padEnd(columnWidths[1], '-')} |\n`;
|
|
205
|
+
model.tables.forEach((table) => {
|
|
206
|
+
const name = `[${table.name}](${table.name}.db.md)`;
|
|
207
|
+
data += `| ${name.padEnd(columnWidths[0], ' ')} | ${table.comment?.padEnd(columnWidths[1], ' ')} |\n`;
|
|
208
|
+
});
|
|
209
|
+
fileHelper_1.FileHelper.writeFileSync(file, data);
|
|
210
|
+
}
|
|
156
211
|
/**
|
|
157
212
|
* Get a model object.
|
|
158
213
|
* @param options the options, required: `database`, `sourceFolder`.
|
|
@@ -168,6 +223,18 @@ class DbmService {
|
|
|
168
223
|
});
|
|
169
224
|
return model;
|
|
170
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Generate markdown files from a database
|
|
228
|
+
* @param dbOptions the datbase connection configure
|
|
229
|
+
* @param markdownFolder the folder to which we will write
|
|
230
|
+
* @param force If true, delete all files whose extension matched, default: `false`.
|
|
231
|
+
* @param fileExtension generated file extension, default: `.db.md`.
|
|
232
|
+
*/
|
|
233
|
+
static async fromDatabase(dbOptions, markdownFolder, force = false, fileExtension = '.db.md') {
|
|
234
|
+
const provider = providerFactory_1.ProviderFactory.getImportProvider(databaseTypes_1.DatabaseTypes.mariadb);
|
|
235
|
+
const model = await provider.getModel(dbOptions);
|
|
236
|
+
this.toMarkdown(model, markdownFolder, force, fileExtension);
|
|
237
|
+
}
|
|
171
238
|
}
|
|
172
239
|
exports.DbmService = DbmService;
|
|
173
240
|
//# sourceMappingURL=dbmService.js.map
|