@dbml/core 2.4.0 → 2.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/lib/export/DbmlExporter.js +2 -5
- package/lib/parse/mssql/keyword_parsers.js +12 -1
- package/lib/parse/mssql/statements/actions.js +28 -0
- package/lib/parse/mssql/statements/index.js +1 -1
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +57 -0
- package/lib/parse/mssql/statements/statement_types/comments/index.js +97 -0
- package/lib/parse/mssql/statements/statement_types/index.js +4 -1
- package/lib/parse/mysql/parser.pegjs +13 -10
- package/lib/parse/mysqlParser.js +267 -144
- package/lib/parse/postgresParser.js +12 -12
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +47 -3
- package/lib/parse/postgresql/Commands/Comment.pegjs +18 -6
- package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +10 -1
- package/lib/parse/postgresql/InitializerUtils.pegjs +4 -2
- package/lib/parse/postgresql/Keywords.pegjs +5 -1
- package/lib/parse/postgresql/parser.pegjs +20 -7
- package/package.json +2 -2
|
@@ -1,11 +1,50 @@
|
|
|
1
|
-
alter_table =
|
|
1
|
+
alter_table = alter_sub_syntax:(
|
|
2
|
+
alter_table_action /
|
|
3
|
+
alter_table_rename /
|
|
4
|
+
alter_table_set_schema /
|
|
5
|
+
alter_table_set_tablespace /
|
|
6
|
+
alter_table_attach /
|
|
7
|
+
alter_table_detach
|
|
8
|
+
) {
|
|
2
9
|
return {
|
|
3
10
|
command_name: "alter_table",
|
|
4
|
-
value:
|
|
11
|
+
value: alter_sub_syntax
|
|
5
12
|
}
|
|
6
13
|
}
|
|
7
14
|
|
|
8
|
-
|
|
15
|
+
alter_table_rename = _ ALTER __ TABLE (__ IF_EXISTS)? (__ ONLY)? __ table_name (_ "*")? __ RENAME (cmt / !semicolon .)* _ semicolon _ {
|
|
16
|
+
return {
|
|
17
|
+
syntax_name: "alter_table_rename",
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
alter_table_set_schema = _ ALTER __ TABLE (__ IF_EXISTS)? __ table_name __ SET __ SCHEMA (cmt / !semicolon .)* _ semicolon _ {
|
|
22
|
+
return {
|
|
23
|
+
syntax_name: "alter_table_set_schema",
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
alter_table_set_tablespace = _ ALTER __ TABLE __ ALL __ IN __ TABLESPACE __ table_name
|
|
28
|
+
(__ OWNED __ BY __ identifier (_ comma _ identifier)*)? __ SET __ TABLESPACE
|
|
29
|
+
(cmt / !semicolon .)* _ semicolon _ {
|
|
30
|
+
return {
|
|
31
|
+
syntax_name: "alter_set_tablespace",
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
alter_table_attach = _ ALTER __ TABLE (__ IF_EXISTS)? __ table_name __ ATTACH __ PARTITION (cmt / !semicolon .)* _ semicolon _ {
|
|
36
|
+
return {
|
|
37
|
+
syntax_name: "alter_table_attach",
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
alter_table_detach = _ ALTER __ TABLE (__ IF_EXISTS)? __ table_name __ DETACH __ PARTITION (cmt / !semicolon .)* _ semicolon _ {
|
|
42
|
+
return {
|
|
43
|
+
syntax_name: "alter_table_detach",
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
alter_table_action = _ ALTER __ TABLE (__ IF_EXISTS)? (__ ONLY)? __ name:table_name (_ "*")? __
|
|
9
48
|
actions:actions _ semicolon _ {
|
|
10
49
|
actions.forEach(({ type, t_value}) => {
|
|
11
50
|
switch(type.toLowerCase()) {
|
|
@@ -79,6 +118,11 @@ action = ADD __ table_constraint:table_constraint (__ NOT __ VALID)? { // reuse
|
|
|
79
118
|
value: value.toLowerCase()
|
|
80
119
|
}
|
|
81
120
|
}
|
|
121
|
+
/ (cmt / !semicolon .)* {
|
|
122
|
+
return {
|
|
123
|
+
type: "unknown",
|
|
124
|
+
}
|
|
125
|
+
}
|
|
82
126
|
|
|
83
127
|
|
|
84
128
|
set_attribute_options = first:set_attribute_option rest:(_ comma _ set_attribute_option)* {
|
|
@@ -2,9 +2,7 @@ comment = _ COMMENT __ ON __ comment_option:comment_option __ IS __ text:(string
|
|
|
2
2
|
_ semicolon _ {
|
|
3
3
|
if (text.toLowerCase() !== "null") {
|
|
4
4
|
comment_option.value.text = text;
|
|
5
|
-
} else
|
|
6
|
-
comment_option.value.syntax_name = "remove_comment";
|
|
7
|
-
}
|
|
5
|
+
} else comment_option.value.text = null;
|
|
8
6
|
|
|
9
7
|
return {
|
|
10
8
|
command_name: "comment",
|
|
@@ -13,12 +11,26 @@ comment = _ COMMENT __ ON __ comment_option:comment_option __ IS __ text:(string
|
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
comment_option = (
|
|
16
|
-
COLUMN __
|
|
14
|
+
COLUMN __ path:(identifier '.')+ column_name:column_name {
|
|
15
|
+
let dbName = null, schemaName = null, tableName;
|
|
16
|
+
if (path.length === 1) {
|
|
17
|
+
tableName = path[0][0];
|
|
18
|
+
} else if (path.length === 2) {
|
|
19
|
+
schemaName = path[0][0];
|
|
20
|
+
tableName = path[1][0];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
dbName = path[0][0];
|
|
24
|
+
schemaName = path[1][0];
|
|
25
|
+
tableName = path[2][0];
|
|
26
|
+
}
|
|
17
27
|
return {
|
|
18
28
|
syntax_name: "column",
|
|
19
29
|
value: {
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
dbName,
|
|
31
|
+
schemaName,
|
|
32
|
+
tableName,
|
|
33
|
+
columnName: column_name
|
|
22
34
|
}
|
|
23
35
|
}
|
|
24
36
|
}
|
|
@@ -8,10 +8,19 @@ ignore_syntax = _ value:(
|
|
|
8
8
|
/ CREATE __ SEQUENCE [^;]* { return { syntax_name: "create_sequence" } }
|
|
9
9
|
/ CREATE __ SCHEMA [^;]* { return { syntax_name: "create_schema" } }
|
|
10
10
|
/ CREATE __ VIEW [^;]* { return { syntax_name: "create_view" } }
|
|
11
|
+
/ ALTER __ (cmt / !(semicolon) .)* { return { syntax_name: "alter_not_table" } }
|
|
11
12
|
/ __ { return { syntax_name: "comment_and_space" } }
|
|
12
13
|
) semicolon _ {
|
|
14
|
+
const loc = location();
|
|
15
|
+
const t = text();
|
|
13
16
|
return {
|
|
14
17
|
command_name: "ignore_syntax",
|
|
15
|
-
value
|
|
18
|
+
value,
|
|
19
|
+
warning: {
|
|
20
|
+
type: 'ignore',
|
|
21
|
+
location: loc,
|
|
22
|
+
text: t,
|
|
23
|
+
message: `ignoring "${t}" at line: ${loc.start.line}`,
|
|
24
|
+
},
|
|
16
25
|
}
|
|
17
26
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
// intput:
|
|
3
|
-
// `
|
|
3
|
+
// `
|
|
4
4
|
// 'created'
|
|
5
|
-
// ,
|
|
5
|
+
// ,
|
|
6
6
|
// 'pending', 'done'
|
|
7
7
|
// `
|
|
8
8
|
// => `'created', 'pending', 'done'`
|
|
@@ -24,4 +24,6 @@
|
|
|
24
24
|
});
|
|
25
25
|
return table;
|
|
26
26
|
};
|
|
27
|
+
|
|
28
|
+
const findField = (table, fieldName) => table.fields.find(field => field.name === fieldName);
|
|
27
29
|
}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
const tables = [];
|
|
3
3
|
const refs = [];
|
|
4
4
|
const enums = [];
|
|
5
|
+
const warnings = [];
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
parser = commands:command* {
|
|
8
|
-
commands.forEach((
|
|
9
|
+
commands.forEach((cmd) => {
|
|
10
|
+
const { command_name, value: { syntax_name, value }, warning } = cmd;
|
|
9
11
|
switch(command_name.toLowerCase()){
|
|
10
12
|
case "create_table":
|
|
11
13
|
const table = value;
|
|
@@ -104,18 +106,29 @@ parser = commands:command* {
|
|
|
104
106
|
break;
|
|
105
107
|
case "comment":
|
|
106
108
|
switch(syntax_name.toLowerCase()) {
|
|
107
|
-
case "column":
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
109
|
+
case "column": {
|
|
110
|
+
const { schemaName, tableName, columnName } = value;
|
|
111
|
+
const foundTable = findTable(schemaName, tableName);
|
|
112
|
+
if (foundTable) {
|
|
113
|
+
const foundField = findField(foundTable, columnName);
|
|
114
|
+
if (foundField) foundField.note = value.text;
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "table": {
|
|
119
|
+
const { schemaName, name: tableName } = value.table_name;
|
|
120
|
+
const foundTable = findTable(schemaName, tableName);
|
|
121
|
+
if (foundTable) foundTable.note = value.text;
|
|
111
122
|
break;
|
|
123
|
+
}
|
|
112
124
|
}
|
|
113
125
|
break;
|
|
114
|
-
case "
|
|
126
|
+
case "ignore_syntax":
|
|
127
|
+
// warnings.push(warning);
|
|
115
128
|
break;
|
|
116
129
|
}
|
|
117
130
|
})
|
|
118
|
-
|
|
131
|
+
|
|
119
132
|
return {tables, refs, enums};
|
|
120
133
|
}
|
|
121
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
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": "4a4ec93db569e677bf15eb53964bd6b26762a421"
|
|
60
60
|
}
|