@dbml/core 2.4.3 → 2.5.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/PostgresExporter.js +6 -3
- package/lib/model_structure/database.js +5 -2
- package/lib/model_structure/enum.js +2 -1
- package/lib/model_structure/enumValue.js +2 -1
- package/lib/model_structure/field.js +4 -3
- package/lib/model_structure/indexes.js +2 -1
- package/lib/model_structure/schema.js +2 -3
- package/lib/model_structure/table.js +2 -1
- package/lib/parse/dbml/parser.pegjs +12 -2
- package/lib/parse/dbmlParser.js +434 -428
- package/lib/parse/mssql/statements/actions.js +10 -6
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +23 -23
- package/lib/parse/mysql/parser.pegjs +9 -9
- package/lib/parse/mysqlParser.js +95 -20
- package/lib/parse/postgresParser.js +6 -6
- package/lib/parse/postgresql/Base_rules.pegjs +1 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +8 -6
- package/lib/parse/postgresql/parser.pegjs +2 -2
- package/package.json +2 -2
- package/types/.DS_Store +0 -0
- package/types/model_structure/database.d.ts +3 -2
- package/types/model_structure/element.d.ts +6 -0
- package/types/model_structure/enum.d.ts +3 -2
- package/types/model_structure/enumValue.d.ts +3 -2
- package/types/model_structure/field.d.ts +6 -2
- package/types/model_structure/indexes.d.ts +3 -2
- package/types/model_structure/schema.d.ts +3 -2
- package/types/model_structure/table.d.ts +3 -2
|
@@ -59,16 +59,14 @@ function handleEnums(_enum, ast) {
|
|
|
59
59
|
}).join(', ');
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function handleComment(comment, ast) {
|
|
63
|
-
if (comment.type === 'table') handleTableNote(comment, ast);else if (comment.type === 'column') handleFieldNote(comment, ast);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
62
|
function handleTableNote(comment, ast) {
|
|
67
63
|
var schemaName = comment.schemaName;
|
|
68
64
|
if (schemaName === 'dbo') schemaName = null; // treat `dbo` as public schema
|
|
69
65
|
|
|
70
66
|
var foundTable = findTable(ast, comment.tableName, schemaName);
|
|
71
|
-
if (foundTable) foundTable.note = comment.note
|
|
67
|
+
if (foundTable) foundTable.note = comment.note ? {
|
|
68
|
+
value: comment.note
|
|
69
|
+
} : null;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
function handleFieldNote(comment, ast) {
|
|
@@ -79,10 +77,16 @@ function handleFieldNote(comment, ast) {
|
|
|
79
77
|
|
|
80
78
|
if (foundTable) {
|
|
81
79
|
var foundField = findField(foundTable, comment.columnName);
|
|
82
|
-
if (foundField) foundField.note = comment.note
|
|
80
|
+
if (foundField) foundField.note = comment.note ? {
|
|
81
|
+
value: comment.note
|
|
82
|
+
} : null;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function handleComment(comment, ast) {
|
|
87
|
+
if (comment.type === 'table') handleTableNote(comment, ast);else if (comment.type === 'column') handleFieldNote(comment, ast);
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
function handleStatement(_statements) {
|
|
87
91
|
var ast = {
|
|
88
92
|
tables: [],
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var isSchema = function isSchema(type) {
|
|
4
|
+
return type.toLowerCase() === 'schema';
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
var isTable = function isTable(type) {
|
|
8
|
+
return type.toLowerCase() === 'table';
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var isColumn = function isColumn(type) {
|
|
12
|
+
return type.toLowerCase() === 'column';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var isValidTableNote = function isValidTableNote(level) {
|
|
16
|
+
return level.length === 2 && isSchema(level[0].type) && isTable(level[1].type);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var isValidColumnNote = function isValidColumnNote(level) {
|
|
20
|
+
return level.length === 3 && isSchema(level[0].type) && isTable(level[1].type) && isColumn(level[2].type);
|
|
21
|
+
};
|
|
22
|
+
|
|
3
23
|
function handleComment(_ref) {
|
|
4
24
|
var note = _ref.note,
|
|
5
25
|
level = _ref.level;
|
|
6
26
|
var type = 'unsupported';
|
|
7
|
-
var schemaName = null
|
|
8
|
-
|
|
9
|
-
|
|
27
|
+
var schemaName = null;
|
|
28
|
+
var tableName = null;
|
|
29
|
+
var columnName = null;
|
|
10
30
|
|
|
11
31
|
if (isValidTableNote(level)) {
|
|
12
32
|
schemaName = level[0].name;
|
|
@@ -32,26 +52,6 @@ function handleComment(_ref) {
|
|
|
32
52
|
};
|
|
33
53
|
}
|
|
34
54
|
|
|
35
|
-
var isSchema = function isSchema(type) {
|
|
36
|
-
return type.toLowerCase() === 'schema';
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var isTable = function isTable(type) {
|
|
40
|
-
return type.toLowerCase() === 'table';
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var isColumn = function isColumn(type) {
|
|
44
|
-
return type.toLowerCase() === 'column';
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
var isValidTableNote = function isValidTableNote(level) {
|
|
48
|
-
return level.length === 2 && isSchema(level[0].type) && isTable(level[1].type);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var isValidColumnNote = function isValidColumnNote(level) {
|
|
52
|
-
return level.length === 3 && isSchema(level[0].type) && isTable(level[1].type) && isColumn(level[2].type);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
55
|
module.exports = {
|
|
56
56
|
handleComment: handleComment
|
|
57
57
|
};
|
|
@@ -86,7 +86,7 @@ TableSyntax
|
|
|
86
86
|
|
|
87
87
|
let res = {...table_name, fields};
|
|
88
88
|
|
|
89
|
-
if (options && options.comment) res.note = options.comment;
|
|
89
|
+
if (options && options.comment) res.note = { value: options.comment };
|
|
90
90
|
if (indexes) res.indexes = indexes;
|
|
91
91
|
// return statement
|
|
92
92
|
return res;
|
|
@@ -190,7 +190,7 @@ UniqueSyntax
|
|
|
190
190
|
// "KEY is normally a synonym for INDEX".
|
|
191
191
|
IndexInLineSyntax = _ unique:index_in_line
|
|
192
192
|
_ name:name? _ type1:index_type? _
|
|
193
|
-
"(" _ columns:IndexColumnValues _")"
|
|
193
|
+
"(" _ columns:IndexColumnValues _")" type2:(_ IndexOption)?
|
|
194
194
|
{
|
|
195
195
|
const index = { columns };
|
|
196
196
|
if(name) {
|
|
@@ -199,9 +199,8 @@ IndexInLineSyntax = _ unique:index_in_line
|
|
|
199
199
|
if(unique) {
|
|
200
200
|
index.unique = true;
|
|
201
201
|
}
|
|
202
|
-
|
|
203
|
-
if(type
|
|
204
|
-
index.type = type;
|
|
202
|
+
if(type2 && type2[1] && type2[1].type === 'index_type' && type2[1].value ) index.type = type2[1].value;
|
|
203
|
+
else if(type1) index.type = type1;
|
|
205
204
|
return index;
|
|
206
205
|
}
|
|
207
206
|
index_in_line // keyword
|
|
@@ -226,12 +225,12 @@ FieldSettings = fieldSettingsArray:FieldSetting*
|
|
|
226
225
|
{
|
|
227
226
|
const fieldSettings = {};
|
|
228
227
|
fieldSettingsArray.forEach(field => {
|
|
229
|
-
if(field === "null")
|
|
228
|
+
if (field === "null")
|
|
230
229
|
fieldSettings["not_null"] = false;
|
|
231
|
-
else if(field.type === "default")
|
|
230
|
+
else if (field.type === "default" && field.value)
|
|
232
231
|
fieldSettings.dbdefault = field.value;
|
|
233
|
-
else if(field.type === "comment")
|
|
234
|
-
fieldSettings.note = field.value;
|
|
232
|
+
else if (field.type === "comment" && field.value)
|
|
233
|
+
fieldSettings.note = { value: field.value };
|
|
235
234
|
else if (field !== "not_supported") {
|
|
236
235
|
fieldSettings[field] = true;
|
|
237
236
|
}
|
|
@@ -257,6 +256,7 @@ FieldSetting "field setting"
|
|
|
257
256
|
) { return "not_supported" }
|
|
258
257
|
/ _ v:Default {return {type: "default", value: v} }
|
|
259
258
|
/ _ v:Comment { return {type: "comment", value: v }}
|
|
259
|
+
/ _ "ON"i _ "UPDATE"i _ type { return "not_supported" }
|
|
260
260
|
|
|
261
261
|
// Default: Support "DEFAULT (value|expr)" syntax
|
|
262
262
|
Default
|
package/lib/parse/mysqlParser.js
CHANGED
|
@@ -197,7 +197,9 @@ function peg$parse(input, options) {
|
|
|
197
197
|
fields: fields
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
if (options && options.comment) res.note =
|
|
200
|
+
if (options && options.comment) res.note = {
|
|
201
|
+
value: options.comment
|
|
202
|
+
};
|
|
201
203
|
if (indexes) res.indexes = indexes; // return statement
|
|
202
204
|
|
|
203
205
|
return res;
|
|
@@ -357,8 +359,7 @@ function peg$parse(input, options) {
|
|
|
357
359
|
index.unique = true;
|
|
358
360
|
}
|
|
359
361
|
|
|
360
|
-
|
|
361
|
-
if (type) index.type = type;
|
|
362
|
+
if (type2 && type2[1] && type2[1].type === 'index_type' && type2[1].value) index.type = type2[1].value;else if (type1) index.type = type1;
|
|
362
363
|
return index;
|
|
363
364
|
},
|
|
364
365
|
peg$c30 = "index",
|
|
@@ -396,7 +397,9 @@ function peg$parse(input, options) {
|
|
|
396
397
|
peg$c41 = function peg$c41(fieldSettingsArray) {
|
|
397
398
|
var fieldSettings = {};
|
|
398
399
|
fieldSettingsArray.forEach(function (field) {
|
|
399
|
-
if (field === "null") fieldSettings["not_null"] = false;else if (field.type === "default") fieldSettings.dbdefault = field.value;else if (field.type === "comment") fieldSettings.note =
|
|
400
|
+
if (field === "null") fieldSettings["not_null"] = false;else if (field.type === "default" && field.value) fieldSettings.dbdefault = field.value;else if (field.type === "comment" && field.value) fieldSettings.note = {
|
|
401
|
+
value: field.value
|
|
402
|
+
};else if (field !== "not_supported") {
|
|
400
403
|
fieldSettings[field] = true;
|
|
401
404
|
}
|
|
402
405
|
});
|
|
@@ -2428,7 +2431,7 @@ function peg$parse(input, options) {
|
|
|
2428
2431
|
}
|
|
2429
2432
|
|
|
2430
2433
|
function peg$parseIndexInLineSyntax() {
|
|
2431
|
-
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
|
|
2434
|
+
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15;
|
|
2432
2435
|
s0 = peg$currPos;
|
|
2433
2436
|
s1 = peg$parse_();
|
|
2434
2437
|
|
|
@@ -2492,27 +2495,32 @@ function peg$parse(input, options) {
|
|
|
2492
2495
|
}
|
|
2493
2496
|
|
|
2494
2497
|
if (s12 !== peg$FAILED) {
|
|
2495
|
-
s13 = peg$
|
|
2498
|
+
s13 = peg$currPos;
|
|
2499
|
+
s14 = peg$parse_();
|
|
2500
|
+
|
|
2501
|
+
if (s14 !== peg$FAILED) {
|
|
2502
|
+
s15 = peg$parseIndexOption();
|
|
2503
|
+
|
|
2504
|
+
if (s15 !== peg$FAILED) {
|
|
2505
|
+
s14 = [s14, s15];
|
|
2506
|
+
s13 = s14;
|
|
2507
|
+
} else {
|
|
2508
|
+
peg$currPos = s13;
|
|
2509
|
+
s13 = peg$FAILED;
|
|
2510
|
+
}
|
|
2511
|
+
} else {
|
|
2512
|
+
peg$currPos = s13;
|
|
2513
|
+
s13 = peg$FAILED;
|
|
2514
|
+
}
|
|
2496
2515
|
|
|
2497
2516
|
if (s13 === peg$FAILED) {
|
|
2498
2517
|
s13 = null;
|
|
2499
2518
|
}
|
|
2500
2519
|
|
|
2501
2520
|
if (s13 !== peg$FAILED) {
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
s14 = null;
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
if (s14 !== peg$FAILED) {
|
|
2509
|
-
peg$savedPos = s0;
|
|
2510
|
-
s1 = peg$c29(s2, s4, s6, s10, s14);
|
|
2511
|
-
s0 = s1;
|
|
2512
|
-
} else {
|
|
2513
|
-
peg$currPos = s0;
|
|
2514
|
-
s0 = peg$FAILED;
|
|
2515
|
-
}
|
|
2521
|
+
peg$savedPos = s0;
|
|
2522
|
+
s1 = peg$c29(s2, s4, s6, s10, s13);
|
|
2523
|
+
s0 = s1;
|
|
2516
2524
|
} else {
|
|
2517
2525
|
peg$currPos = s0;
|
|
2518
2526
|
s0 = peg$FAILED;
|
|
@@ -3689,6 +3697,73 @@ function peg$parse(input, options) {
|
|
|
3689
3697
|
peg$currPos = s0;
|
|
3690
3698
|
s0 = peg$FAILED;
|
|
3691
3699
|
}
|
|
3700
|
+
|
|
3701
|
+
if (s0 === peg$FAILED) {
|
|
3702
|
+
s0 = peg$currPos;
|
|
3703
|
+
s1 = peg$parse_();
|
|
3704
|
+
|
|
3705
|
+
if (s1 !== peg$FAILED) {
|
|
3706
|
+
if (input.substr(peg$currPos, 2).toLowerCase() === peg$c17) {
|
|
3707
|
+
s2 = input.substr(peg$currPos, 2);
|
|
3708
|
+
peg$currPos += 2;
|
|
3709
|
+
} else {
|
|
3710
|
+
s2 = peg$FAILED;
|
|
3711
|
+
|
|
3712
|
+
if (peg$silentFails === 0) {
|
|
3713
|
+
peg$fail(peg$c18);
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
|
|
3717
|
+
if (s2 !== peg$FAILED) {
|
|
3718
|
+
s3 = peg$parse_();
|
|
3719
|
+
|
|
3720
|
+
if (s3 !== peg$FAILED) {
|
|
3721
|
+
if (input.substr(peg$currPos, 6).toLowerCase() === peg$c19) {
|
|
3722
|
+
s4 = input.substr(peg$currPos, 6);
|
|
3723
|
+
peg$currPos += 6;
|
|
3724
|
+
} else {
|
|
3725
|
+
s4 = peg$FAILED;
|
|
3726
|
+
|
|
3727
|
+
if (peg$silentFails === 0) {
|
|
3728
|
+
peg$fail(peg$c20);
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
|
|
3732
|
+
if (s4 !== peg$FAILED) {
|
|
3733
|
+
s5 = peg$parse_();
|
|
3734
|
+
|
|
3735
|
+
if (s5 !== peg$FAILED) {
|
|
3736
|
+
s6 = peg$parsetype();
|
|
3737
|
+
|
|
3738
|
+
if (s6 !== peg$FAILED) {
|
|
3739
|
+
peg$savedPos = s0;
|
|
3740
|
+
s1 = peg$c79();
|
|
3741
|
+
s0 = s1;
|
|
3742
|
+
} else {
|
|
3743
|
+
peg$currPos = s0;
|
|
3744
|
+
s0 = peg$FAILED;
|
|
3745
|
+
}
|
|
3746
|
+
} else {
|
|
3747
|
+
peg$currPos = s0;
|
|
3748
|
+
s0 = peg$FAILED;
|
|
3749
|
+
}
|
|
3750
|
+
} else {
|
|
3751
|
+
peg$currPos = s0;
|
|
3752
|
+
s0 = peg$FAILED;
|
|
3753
|
+
}
|
|
3754
|
+
} else {
|
|
3755
|
+
peg$currPos = s0;
|
|
3756
|
+
s0 = peg$FAILED;
|
|
3757
|
+
}
|
|
3758
|
+
} else {
|
|
3759
|
+
peg$currPos = s0;
|
|
3760
|
+
s0 = peg$FAILED;
|
|
3761
|
+
}
|
|
3762
|
+
} else {
|
|
3763
|
+
peg$currPos = s0;
|
|
3764
|
+
s0 = peg$FAILED;
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3692
3767
|
}
|
|
3693
3768
|
}
|
|
3694
3769
|
}
|