@dbml/core 2.3.1 → 2.4.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/lib/export/DbmlExporter.js +9 -1
- package/lib/export/MysqlExporter.js +41 -35
- package/lib/export/PostgresExporter.js +55 -42
- package/lib/export/SqlServerExporter.js +43 -39
- package/lib/model_structure/database.js +53 -12
- package/lib/model_structure/endpoint.js +2 -2
- package/lib/model_structure/field.js +31 -1
- package/lib/model_structure/ref.js +1 -2
- package/lib/model_structure/schema.js +3 -19
- package/lib/model_structure/tableGroup.js +1 -1
- package/lib/model_structure/utils.js +5 -0
- package/lib/parse/dbml/parser.pegjs +61 -19
- package/lib/parse/dbmlParser.js +1219 -883
- package/lib/parse/mssql/fk_definition/actions.js +10 -3
- package/lib/parse/mssql/statements/actions.js +9 -6
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +11 -5
- package/lib/parse/mssql/statements/statement_types/create_index/actions.js +6 -1
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +11 -9
- package/lib/parse/mssql/utils.js +15 -0
- package/lib/parse/mysql/parser.pegjs +46 -14
- package/lib/parse/mysqlParser.js +215 -167
- package/lib/parse/postgresParser.js +11 -10
- package/lib/parse/postgresql/Base_rules.pegjs +24 -3
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +2 -1
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +5 -3
- package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +1 -1
- package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +1 -1
- package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +2 -2
- package/lib/parse/postgresql/InitializerUtils.pegjs +10 -0
- package/lib/parse/postgresql/parser.pegjs +2 -1
- package/package.json +2 -2
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
// Base rules:
|
|
2
2
|
// collumn_name, table_name
|
|
3
3
|
column_name "valid column name" = identifier
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
path_name = names:(identifier _ "." _)* {
|
|
6
|
+
let dbName = null;
|
|
7
|
+
let schemaName = null;
|
|
8
|
+
if (names && names.length > 0) {
|
|
9
|
+
if (names.length === 1) schemaName = names[0][0];
|
|
10
|
+
else {
|
|
11
|
+
dbName = names[0][0];
|
|
12
|
+
schemaName = names[1][0];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return { dbName, schemaName }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
table_name "valid table name" = pathName:path_name name:identifier {
|
|
19
|
+
return { ...pathName, name }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
enum_name "valid enum name" = pathName:path_name? name:identifier {
|
|
23
|
+
return { ...pathName, name }
|
|
24
|
+
}
|
|
6
25
|
|
|
7
26
|
// string constant
|
|
8
27
|
string_constant "string" = "'" c:char_inside_single_quote+ "'" {
|
|
@@ -58,6 +77,7 @@ data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")
|
|
|
58
77
|
const args = c.args;
|
|
59
78
|
return {
|
|
60
79
|
type_name: c.type_name + (dimensions ? dimensions.map((dimension) => '[' + dimension + ']').join('') : ''),
|
|
80
|
+
schemaName: c.schemaName,
|
|
61
81
|
args
|
|
62
82
|
};
|
|
63
83
|
}
|
|
@@ -67,7 +87,7 @@ data_type "VALID TYPE" = c1:"CHARACTER"i _ c2:"VARYING"i _ args:("("expression")
|
|
|
67
87
|
args: null
|
|
68
88
|
}
|
|
69
89
|
}
|
|
70
|
-
type_name = c:(character)+ _ args:("(" expression ")")? {
|
|
90
|
+
type_name = pathName:path_name? c:(character)+ _ args:("(" expression ")")? {
|
|
71
91
|
let type_name = c.join("");
|
|
72
92
|
args = args ? args[1] : null;
|
|
73
93
|
if (type_name.toLowerCase() !== 'enum') {
|
|
@@ -75,6 +95,7 @@ type_name = c:(character)+ _ args:("(" expression ")")? {
|
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
return {
|
|
98
|
+
...pathName,
|
|
78
99
|
type_name,
|
|
79
100
|
args
|
|
80
101
|
}
|
|
@@ -11,7 +11,8 @@ alter_table_action = _ ALTER __ TABLE (__ IF_EXISTS)? (__ ONLY)? __ name:table_n
|
|
|
11
11
|
switch(type.toLowerCase()) {
|
|
12
12
|
case "fk":
|
|
13
13
|
t_value.forEach(({ endpoints }) => {
|
|
14
|
-
endpoints[0].tableName = name
|
|
14
|
+
endpoints[0].tableName = name.name;
|
|
15
|
+
endpoints[0].schemaName = name.schemaName;
|
|
15
16
|
})
|
|
16
17
|
}
|
|
17
18
|
})
|
|
@@ -7,7 +7,7 @@ create_table_normal =
|
|
|
7
7
|
(__ ON __ COMMIT __ (PRESERVE __ ROWS/ DELETE __ ROWS/ DROP))?
|
|
8
8
|
(__ TABLESPACE __ tablespace_name:identifier)?
|
|
9
9
|
_ semicolon _ {
|
|
10
|
-
const table = { name: table_name, fields: [], indexes: [] }
|
|
10
|
+
const table = { name: table_name.name, schemaName: table_name.schemaName, fields: [], indexes: [] }
|
|
11
11
|
// process table_properties
|
|
12
12
|
table_properties.forEach(({ table_property_name, value }) => {
|
|
13
13
|
switch(table_property_name.toLowerCase()) {
|
|
@@ -156,7 +156,8 @@ column_constraint = (CONSTRAINT __ constraint_name:identifier __)?
|
|
|
156
156
|
type: "fk",
|
|
157
157
|
value: {
|
|
158
158
|
endpoint: {
|
|
159
|
-
tableName: reftable,
|
|
159
|
+
tableName: reftable.name,
|
|
160
|
+
schemaName: reftable.schemaName,
|
|
160
161
|
fieldNames: refcolumn ? [refcolumn] : null,
|
|
161
162
|
relation: "1"
|
|
162
163
|
},
|
|
@@ -192,7 +193,8 @@ table_constraint = (CONSTRAINT __ constraint_name:identifier __)?
|
|
|
192
193
|
relation: "*",
|
|
193
194
|
},
|
|
194
195
|
{
|
|
195
|
-
tableName: reftable,
|
|
196
|
+
tableName: reftable.name,
|
|
197
|
+
schemaName: reftable.schemaName,
|
|
196
198
|
fieldNames: refcolumn,// ? refcolumn[key] : null,
|
|
197
199
|
relation: "1",
|
|
198
200
|
},
|
|
@@ -6,7 +6,7 @@ create_table_of =
|
|
|
6
6
|
(__ ON __ COMMIT __ (PRESERVE __ ROWS/ DELETE __ ROWS/ DROP))?
|
|
7
7
|
(__ TABLESPACE __ tablespace_name:identifier)?
|
|
8
8
|
_ semicolon _ {
|
|
9
|
-
const table = { name: table_name, type: type_name}
|
|
9
|
+
const table = { name: table_name.name, schemaName: table_name.schemaName, type: type_name}
|
|
10
10
|
return {
|
|
11
11
|
syntax_name: "create_table_of",
|
|
12
12
|
value: table
|
|
@@ -7,7 +7,7 @@ create_table_partition_of =
|
|
|
7
7
|
(__ ON __ COMMIT __ (PRESERVE __ ROWS/ DELETE __ ROWS/ DROP))?
|
|
8
8
|
(__ TABLESPACE __ tablespace_name:identifier)?
|
|
9
9
|
_ semicolon _ {
|
|
10
|
-
const table = { name: table_name, parent_table: parent_table}
|
|
10
|
+
const table = { name: table_name.name, schemaName: table_name.schemaName, parent_table: parent_table}
|
|
11
11
|
return {
|
|
12
12
|
syntax_name: "create_table_partition_of",
|
|
13
13
|
value: table
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
create_type_enum =
|
|
2
|
-
_ CREATE __ TYPE __
|
|
2
|
+
_ CREATE __ TYPE __ enumName:enum_name __ AS __ ENUM _
|
|
3
3
|
"(" _ labels:labels _ ")"
|
|
4
4
|
_ semicolon _ {
|
|
5
5
|
const values = labels.map(name => ({ name }))
|
|
6
6
|
return {
|
|
7
7
|
syntax_name: "create_type_enum",
|
|
8
8
|
value: {
|
|
9
|
-
|
|
9
|
+
...enumName,
|
|
10
10
|
values,
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -14,4 +14,14 @@
|
|
|
14
14
|
});
|
|
15
15
|
return arrAfterTrim.join(', ');
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
// TODO: support configurable default schema name other than 'public'
|
|
19
|
+
const findTable = (schemaName, tableName) => {
|
|
20
|
+
const realSchemaName = schemaName || 'public';
|
|
21
|
+
const table = tables.find(table => {
|
|
22
|
+
const targetSchemaName = table.schemaName || 'public';
|
|
23
|
+
return targetSchemaName === realSchemaName && table.name === tableName;
|
|
24
|
+
});
|
|
25
|
+
return table;
|
|
26
|
+
};
|
|
17
27
|
}
|
|
@@ -23,6 +23,7 @@ parser = commands:command* {
|
|
|
23
23
|
endpoints: [
|
|
24
24
|
{
|
|
25
25
|
tableName: table.name,
|
|
26
|
+
schemaName: table.schemaName,
|
|
26
27
|
fieldNames: [field.name],
|
|
27
28
|
relation: "*",
|
|
28
29
|
},
|
|
@@ -70,7 +71,7 @@ parser = commands:command* {
|
|
|
70
71
|
case "create_index":
|
|
71
72
|
const { table_name } = value;
|
|
72
73
|
delete value.table_name; // remove table_name from column
|
|
73
|
-
|
|
74
|
+
const table_index = findTable(table_name.schemaName, table_name.name);
|
|
74
75
|
if (table_index.indexes) {
|
|
75
76
|
table_index.indexes.push(value);
|
|
76
77
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"\\.(?!json$)[^.]*$": "jest-raw-loader"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "bbc1d589c6dcefce089bd6007a24cad2808a3818"
|
|
60
60
|
}
|