@dbml/core 2.5.2 → 2.5.4
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/README.md +1 -1
- package/lib/export/DbmlExporter.js +9 -64
- package/lib/export/JsonExporter.js +5 -11
- package/lib/export/ModelExporter.js +5 -22
- package/lib/export/MysqlExporter.js +8 -70
- package/lib/export/PostgresExporter.js +11 -80
- package/lib/export/SqlServerExporter.js +10 -71
- package/lib/export/index.js +0 -6
- package/lib/export/utils.js +2 -12
- package/lib/import/index.js +0 -7
- package/lib/index.js +4 -9
- package/lib/model_structure/config.js +1 -1
- package/lib/model_structure/database.js +32 -83
- package/lib/model_structure/dbState.js +5 -10
- package/lib/model_structure/element.js +13 -38
- package/lib/model_structure/endpoint.js +22 -68
- package/lib/model_structure/enum.js +18 -49
- package/lib/model_structure/enumValue.js +17 -44
- package/lib/model_structure/field.js +26 -62
- package/lib/model_structure/indexColumn.js +15 -40
- package/lib/model_structure/indexes.js +22 -50
- package/lib/model_structure/ref.js +24 -56
- package/lib/model_structure/schema.js +27 -65
- package/lib/model_structure/table.js +24 -59
- package/lib/model_structure/tableGroup.js +18 -49
- package/lib/model_structure/utils.js +0 -3
- package/lib/parse/Parser.js +5 -27
- package/lib/parse/buildParser.js +11 -23
- package/lib/parse/dbmlParser.js +863 -2131
- package/lib/parse/mssql/base_parsers.js +2 -11
- package/lib/parse/mssql/column_definition/actions.js +0 -3
- package/lib/parse/mssql/column_definition/index.js +9 -17
- package/lib/parse/mssql/constraint_definition/actions.js +6 -12
- package/lib/parse/mssql/constraint_definition/index.js +13 -21
- package/lib/parse/mssql/expression.js +6 -16
- package/lib/parse/mssql/fk_definition/actions.js +1 -12
- package/lib/parse/mssql/fk_definition/index.js +5 -10
- package/lib/parse/mssql/index.js +2 -4
- package/lib/parse/mssql/index_definition/actions.js +0 -6
- package/lib/parse/mssql/index_definition/index.js +8 -13
- package/lib/parse/mssql/keyword_parsers.js +2 -3
- package/lib/parse/mssql/keyword_utils.js +0 -4
- package/lib/parse/mssql/statements/actions.js +0 -24
- package/lib/parse/mssql/statements/index.js +1 -7
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +3 -10
- package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +2 -6
- package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +9 -18
- package/lib/parse/mssql/statements/statement_types/alter_table/index.js +2 -7
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +3 -11
- package/lib/parse/mssql/statements/statement_types/comments/index.js +3 -13
- package/lib/parse/mssql/statements/statement_types/create_index/actions.js +1 -3
- package/lib/parse/mssql/statements/statement_types/create_index/index.js +9 -15
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +7 -18
- package/lib/parse/mssql/statements/statement_types/create_table/index.js +8 -16
- package/lib/parse/mssql/statements/statement_types/index.js +0 -4
- package/lib/parse/mssql/utils.js +4 -14
- package/lib/parse/mssql/whitespaces.js +0 -1
- package/lib/parse/mssqlParser.js +0 -3
- package/lib/parse/mysqlParser.js +822 -2395
- package/lib/parse/postgresParser.js +3 -3
- package/lib/parse/postgresql/get_parser.js +6 -9
- package/lib/parse/schemarbParser.js +219 -714
- package/package.json +11 -12
- package/types/.DS_Store +0 -0
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var _require = require('./utils'),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
makeList = _require.makeList,
|
|
6
|
+
streamline = _require.streamline;
|
|
9
7
|
var KP = require('./keyword_parsers');
|
|
10
|
-
|
|
11
8
|
var wss = require('./whitespaces');
|
|
12
|
-
|
|
13
9
|
var _pIgnore = P(function (input, i) {
|
|
14
10
|
var j = i;
|
|
15
11
|
var isEnclosed = false;
|
|
16
12
|
var encloseChar = '';
|
|
17
|
-
|
|
18
13
|
while (j < input.length && (isEnclosed || !input.slice(j, j + 2).match(/GO|;/i))) {
|
|
19
14
|
if (isEnclosed && input[j].match(/\]|'|"/i) && input[j] === encloseChar) {
|
|
20
15
|
isEnclosed = false;
|
|
@@ -23,18 +18,14 @@ var _pIgnore = P(function (input, i) {
|
|
|
23
18
|
encloseChar = input[j];
|
|
24
19
|
if (input[j] === '[') encloseChar = ']';
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
if (!input[j].match(/\s/)) j += 1;
|
|
28
|
-
|
|
29
22
|
while (j < input.length && input[j].match(/\s/)) {
|
|
30
23
|
j += 1;
|
|
31
24
|
}
|
|
32
25
|
}
|
|
33
|
-
|
|
34
26
|
if (input.slice(j, j + 2).match(/GO/i)) j -= 1;
|
|
35
27
|
return P.makeSuccess(j + 1, '');
|
|
36
28
|
});
|
|
37
|
-
|
|
38
29
|
var Lang = P.createLanguage({
|
|
39
30
|
pIgnore: function pIgnore() {
|
|
40
31
|
return _pIgnore;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
|
-
|
|
5
4
|
function makeDataType(typeName, args) {
|
|
6
5
|
var argsString = args ? args.join(',') : null;
|
|
7
6
|
return {
|
|
@@ -13,7 +12,6 @@ function makeDataType(typeName, args) {
|
|
|
13
12
|
}
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
function makeColumn(fieldName, dataType, fieldSettings) {
|
|
18
16
|
var value = {};
|
|
19
17
|
value[dataType.type] = dataType.value;
|
|
@@ -27,7 +25,6 @@ function makeColumn(fieldName, dataType, fieldSettings) {
|
|
|
27
25
|
value: value
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
module.exports = {
|
|
32
29
|
makeColumn: makeColumn,
|
|
33
30
|
makeDataType: makeDataType
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var KP = require('../keyword_parsers');
|
|
6
|
-
|
|
7
5
|
var _require = require('../base_parsers'),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
pDotDelimitedName = _require.pDotDelimitedName,
|
|
7
|
+
pIdentifier = _require.pIdentifier,
|
|
8
|
+
pNumberList = _require.pNumberList,
|
|
9
|
+
pOptionList = _require.pOptionList;
|
|
13
10
|
var _require2 = require('../utils'),
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
makeNode = _require2.makeNode,
|
|
12
|
+
makeList = _require2.makeList,
|
|
13
|
+
streamline = _require2.streamline;
|
|
18
14
|
var _require3 = require('../index_definition'),
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
pColumnIndex = _require3.pColumnIndex;
|
|
21
16
|
var _require4 = require('../constraint_definition'),
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
pColumnConstraint = _require4.pColumnConstraint;
|
|
24
18
|
var pExpression = require('../expression');
|
|
25
|
-
|
|
26
19
|
var A = require('./actions');
|
|
27
|
-
|
|
28
20
|
var Lang = P.createLanguage({
|
|
29
21
|
ColumnsDefinition: function ColumnsDefinition(r) {
|
|
30
22
|
return P.alt(r.ComputedColumnDefinition.result(null), r.ColumnSetDefinition.result(null), r.ColumnDefinition);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
8
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
9
|
function makeDefaultConstraint(_keyword, constExpression) {
|
|
10
10
|
var value = {};
|
|
11
|
-
|
|
12
11
|
if (constExpression.type) {
|
|
13
12
|
switch (constExpression.type) {
|
|
14
13
|
case 'string':
|
|
@@ -16,7 +15,6 @@ function makeDefaultConstraint(_keyword, constExpression) {
|
|
|
16
15
|
case 'boolean':
|
|
17
16
|
value.type = constExpression.type;
|
|
18
17
|
break;
|
|
19
|
-
|
|
20
18
|
default:
|
|
21
19
|
value.type = 'expression';
|
|
22
20
|
break;
|
|
@@ -24,14 +22,12 @@ function makeDefaultConstraint(_keyword, constExpression) {
|
|
|
24
22
|
} else {
|
|
25
23
|
value.type = 'expression';
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
value.value = constExpression.value;
|
|
29
26
|
return {
|
|
30
27
|
type: 'dbdefault',
|
|
31
28
|
value: value
|
|
32
29
|
};
|
|
33
30
|
}
|
|
34
|
-
|
|
35
31
|
function makeConstraintCheckEnum(fieldName, _ununsed, values) {
|
|
36
32
|
var valuesProp = [];
|
|
37
33
|
values.forEach(function (value) {
|
|
@@ -46,7 +42,6 @@ function makeConstraintCheckEnum(fieldName, _ununsed, values) {
|
|
|
46
42
|
name: "".concat(fieldName, "_enum"),
|
|
47
43
|
values: valuesProp,
|
|
48
44
|
fieldName: fieldName // for alter table add enum
|
|
49
|
-
|
|
50
45
|
}
|
|
51
46
|
};
|
|
52
47
|
}
|
|
@@ -60,7 +55,6 @@ function makeTableConstraint(constraintName, option) {
|
|
|
60
55
|
})
|
|
61
56
|
};
|
|
62
57
|
}
|
|
63
|
-
|
|
64
58
|
module.exports = {
|
|
65
59
|
makeConstraintCheckEnum: makeConstraintCheckEnum,
|
|
66
60
|
makeDefaultConstraint: makeDefaultConstraint,
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var KP = require('../keyword_parsers');
|
|
6
|
-
|
|
7
5
|
var pExpression = require('../expression');
|
|
8
|
-
|
|
9
6
|
var _require = require('../base_parsers'),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
pIdentifier = _require.pIdentifier,
|
|
8
|
+
pConst = _require.pConst,
|
|
9
|
+
pFunction = _require.pFunction;
|
|
14
10
|
var _require2 = require('../utils'),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
makeList = _require2.makeList,
|
|
12
|
+
streamline = _require2.streamline,
|
|
13
|
+
makeNode = _require2.makeNode;
|
|
19
14
|
var _require3 = require('../fk_definition'),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
pColumnConstraintFK = _require3.pColumnConstraintFK,
|
|
16
|
+
pTableConstraintFK = _require3.pTableConstraintFK;
|
|
23
17
|
var _require4 = require('../index_definition'),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
pColumnConstraintIndex = _require4.pColumnConstraintIndex,
|
|
19
|
+
pTableConstraintIndex = _require4.pTableConstraintIndex;
|
|
27
20
|
var A = require('./actions');
|
|
28
|
-
|
|
29
21
|
var Lang = P.createLanguage({
|
|
30
22
|
TableConstraint: function TableConstraint(r) {
|
|
31
23
|
return P.seqMap(r.ConstraintName.fallback(null), r.TableConstraintOption, A.makeTableConstraint).thru(makeNode());
|
|
@@ -57,10 +49,10 @@ var Lang = P.createLanguage({
|
|
|
57
49
|
ConstraintDefault: function ConstraintDefault(r) {
|
|
58
50
|
return P.seqMap(KP.KeywordDefault, r.ConstExpr, A.makeDefaultConstraint);
|
|
59
51
|
},
|
|
60
|
-
ConstExpr: function ConstExpr() {
|
|
61
|
-
return P.seq(KP.LParen
|
|
52
|
+
ConstExpr: function ConstExpr(r) {
|
|
53
|
+
return P.alt(P.seq(KP.LParen, r.ConstExpr, KP.RParen).map(function (value) {
|
|
62
54
|
return value[1];
|
|
63
|
-
});
|
|
55
|
+
}), pFunction, pConst, KP.KeywordNull.thru(streamline('boolean')));
|
|
64
56
|
},
|
|
65
57
|
ConstraintName: function ConstraintName() {
|
|
66
58
|
return P.seq(KP.KeywordConstraint, pIdentifier).map(function (value) {
|
|
@@ -1,44 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var _ = require('lodash');
|
|
6
|
-
|
|
7
5
|
var _require = require('./base_parsers'),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
pFunction = _require.pFunction,
|
|
7
|
+
pDotDelimitedName = _require.pDotDelimitedName,
|
|
8
|
+
pConst = _require.pConst;
|
|
12
9
|
var _require2 = require('./keyword_parsers'),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
LParen = _require2.LParen,
|
|
11
|
+
RParen = _require2.RParen;
|
|
16
12
|
var wss = require('./whitespaces');
|
|
17
|
-
|
|
18
13
|
var _require3 = require('./utils'),
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
streamline = _require3.streamline;
|
|
21
15
|
function tokenizeParen(parser) {
|
|
22
16
|
return parser.many().map(function (value) {
|
|
23
17
|
return value.join('');
|
|
24
18
|
}).fallback(null).thru(streamline('token'));
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
function enclose(parser) {
|
|
28
21
|
var ManyRParen = RParen.thru(tokenizeParen);
|
|
29
22
|
var ManyLParen = LParen.thru(tokenizeParen);
|
|
30
23
|
return P.seq(ManyLParen, parser, ManyRParen);
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
function enclosedOrNot(parser) {
|
|
34
26
|
return P.alt(enclose(parser), parser);
|
|
35
27
|
}
|
|
36
|
-
|
|
37
28
|
var Lang = P.createLanguage({
|
|
38
29
|
ExpressionFinal: function ExpressionFinal(r) {
|
|
39
30
|
return r.Expression.map(function (values) {
|
|
40
31
|
var flattened = _.flattenDeep(values);
|
|
41
|
-
|
|
42
32
|
return flattened.map(function (value) {
|
|
43
33
|
return value ? value.value : '';
|
|
44
34
|
}).join('');
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
|
-
|
|
5
4
|
var _require = require('../utils'),
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
getFullTableName = _require.getFullTableName;
|
|
8
6
|
function makeEndPoint(tableName, columnName, relation) {
|
|
9
7
|
return {
|
|
10
8
|
tableName: tableName.name,
|
|
@@ -13,19 +11,16 @@ function makeEndPoint(tableName, columnName, relation) {
|
|
|
13
11
|
relation: relation
|
|
14
12
|
};
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
function setOption(value, fkOptions) {
|
|
18
15
|
fkOptions.forEach(function (option) {
|
|
19
16
|
if (option.type.match(/ON[^\S\r\n]DELETE/i)) {
|
|
20
17
|
value.onDelete = option.setting;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
if (option.type.match(/ON[^\S\r\n]UPDATE/i)) {
|
|
24
20
|
value.onUpdate = option.setting;
|
|
25
21
|
}
|
|
26
22
|
});
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
function makeColumnConstraintFK(_unused, tableName, columnName, fkOptions) {
|
|
30
25
|
var value = {};
|
|
31
26
|
var fullTableName = getFullTableName(tableName);
|
|
@@ -36,7 +31,6 @@ function makeColumnConstraintFK(_unused, tableName, columnName, fkOptions) {
|
|
|
36
31
|
value: [value]
|
|
37
32
|
};
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
function makeTableEndpoint(columnNames) {
|
|
41
35
|
return {
|
|
42
36
|
type: 'endpoint',
|
|
@@ -45,11 +39,9 @@ function makeTableEndpoint(columnNames) {
|
|
|
45
39
|
}
|
|
46
40
|
};
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
function makeTableConstraintFK(_keyword1, endpoint1, _keyword2, tableName, endpoint2, fkOptions) {
|
|
50
43
|
var value = {};
|
|
51
44
|
var fullTableName = getFullTableName(tableName);
|
|
52
|
-
|
|
53
45
|
if (!endpoint2) {
|
|
54
46
|
// Omits columns list, see: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver16#foreign-key-constraints
|
|
55
47
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -60,7 +52,6 @@ function makeTableConstraintFK(_keyword1, endpoint1, _keyword2, tableName, endpo
|
|
|
60
52
|
}
|
|
61
53
|
};
|
|
62
54
|
}
|
|
63
|
-
|
|
64
55
|
endpoint1.value.relation = '*';
|
|
65
56
|
endpoint2.value.relation = '1';
|
|
66
57
|
endpoint2.value.tableName = fullTableName.name;
|
|
@@ -72,14 +63,12 @@ function makeTableConstraintFK(_keyword1, endpoint1, _keyword2, tableName, endpo
|
|
|
72
63
|
value: value
|
|
73
64
|
};
|
|
74
65
|
}
|
|
75
|
-
|
|
76
66
|
function makeOnSetting(type, setting) {
|
|
77
67
|
return {
|
|
78
68
|
type: type,
|
|
79
69
|
setting: setting.toLowerCase().trim().split(/[ ]+/).join(' ')
|
|
80
70
|
};
|
|
81
71
|
}
|
|
82
|
-
|
|
83
72
|
module.exports = {
|
|
84
73
|
makeOnSetting: makeOnSetting,
|
|
85
74
|
makeColumnConstraintFK: makeColumnConstraintFK,
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var KP = require('../keyword_parsers');
|
|
6
|
-
|
|
7
5
|
var _require = require('../base_parsers'),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
pDotDelimitedName = _require.pDotDelimitedName,
|
|
7
|
+
pIdentifier = _require.pIdentifier,
|
|
8
|
+
pColumnNames = _require.pColumnNames;
|
|
12
9
|
var _require2 = require('../utils'),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
makeList = _require2.makeList,
|
|
11
|
+
makeNode = _require2.makeNode;
|
|
16
12
|
var A = require('./actions');
|
|
17
|
-
|
|
18
13
|
var Lang = P.createLanguage({
|
|
19
14
|
TableConstraintFK: function TableConstraintFK(r) {
|
|
20
15
|
return P.seqMap(KP.KeywordForeignKey.fallback(null), r.TableEndpoint, KP.KeywordReferences, pDotDelimitedName, r.TableEndpoint.fallback(null), r.FKOptions.fallback(null), A.makeTableConstraintFK);
|
package/lib/parse/mssql/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var mssqlParser = require('./statements');
|
|
4
|
-
|
|
5
4
|
mssqlParser.parseWithPegError = function (input) {
|
|
6
5
|
try {
|
|
7
6
|
return mssqlParser.tryParse(input);
|
|
@@ -15,10 +14,9 @@ mssqlParser.parseWithPegError = function (input) {
|
|
|
15
14
|
pegJSError.found = input[pegJSError.location.start.offset];
|
|
16
15
|
var lastExpected = err.result.expected.pop();
|
|
17
16
|
var expectedString = "".concat(err.result.expected.join(', '), ", or ").concat(lastExpected);
|
|
18
|
-
pegJSError.message = "Expected ".concat(expectedString, " but \"").concat(pegJSError.found, "\" found.");
|
|
19
|
-
|
|
17
|
+
pegJSError.message = "Expected ".concat(expectedString, " but \"").concat(pegJSError.found, "\" found.");
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
20
19
|
throw pegJSError;
|
|
21
20
|
}
|
|
22
21
|
};
|
|
23
|
-
|
|
24
22
|
module.exports = mssqlParser;
|
|
@@ -19,7 +19,6 @@ function makeIndex(columnNames, isUnique, isPk) {
|
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
function makeColumnIndex(_keyword, indexName) {
|
|
24
23
|
return {
|
|
25
24
|
type: 'indexes',
|
|
@@ -29,24 +28,19 @@ function makeColumnIndex(_keyword, indexName) {
|
|
|
29
28
|
}
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
function makeTableIndex(_keyword, indexName, isUnique, _clustered, _columnstore, columnNames) {
|
|
34
32
|
return makeIndex(columnNames, isUnique, null, indexName);
|
|
35
33
|
}
|
|
36
|
-
|
|
37
34
|
function makeTableConstraintIndex(keyword, _keyword, columnNames) {
|
|
38
35
|
var isPk = null;
|
|
39
36
|
var isUnique = null;
|
|
40
|
-
|
|
41
37
|
if (keyword.type === 'pk') {
|
|
42
38
|
isPk = true;
|
|
43
39
|
} else if (keyword.type === 'unique') {
|
|
44
40
|
isUnique = true;
|
|
45
41
|
}
|
|
46
|
-
|
|
47
42
|
return makeIndex(columnNames, isUnique, isPk);
|
|
48
43
|
}
|
|
49
|
-
|
|
50
44
|
module.exports = {
|
|
51
45
|
makeTableIndex: makeTableIndex,
|
|
52
46
|
makeTableConstraintIndex: makeTableConstraintIndex,
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var KP = require('../keyword_parsers');
|
|
6
|
-
|
|
7
5
|
var _require = require('../base_parsers'),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
pIdentifier = _require.pIdentifier,
|
|
7
|
+
pKeywordClusteredOrNon = _require.pKeywordClusteredOrNon,
|
|
8
|
+
pFunction = _require.pFunction,
|
|
9
|
+
pOptionList = _require.pOptionList,
|
|
10
|
+
pColumnNames = _require.pColumnNames,
|
|
11
|
+
pKeywordPKOrUnique = _require.pKeywordPKOrUnique,
|
|
12
|
+
pOption = _require.pOption;
|
|
16
13
|
var _require2 = require('../utils'),
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
makeNode = _require2.makeNode;
|
|
19
15
|
var A = require('./actions');
|
|
20
|
-
|
|
21
16
|
var Lang = P.createLanguage({
|
|
22
17
|
TableIndex: function TableIndex(r) {
|
|
23
18
|
return P.seqMap(KP.KeywordIndex, pIdentifier, KP.KeywordUnique.fallback(null), pKeywordClusteredOrNon.fallback(null), KP.KeywordColumnStore.fallback(null), pColumnNames, A.makeTableIndex).thru(makeNode()).skip(r.IgnoredIndexOptions);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _require = require('./keyword_utils'),
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
keyword = _require.keyword,
|
|
5
|
+
word = _require.word;
|
|
7
6
|
exports.KeywordIdentity = keyword(/IDENTITY/i);
|
|
8
7
|
exports.KeywordIndex = keyword(/INDEX/i);
|
|
9
8
|
exports.KeywordWith = keyword(/WITH/i);
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var wss = require('./whitespaces');
|
|
6
|
-
|
|
7
5
|
exports.word = function (string) {
|
|
8
6
|
return P.string(string).skip(wss).desc("\"".concat(string, "\""));
|
|
9
7
|
};
|
|
10
|
-
|
|
11
8
|
function replaceWhitespaceWithRegexp(regexp) {
|
|
12
9
|
var string = String(regexp);
|
|
13
10
|
string = string.replace(/[\s]+/g, '\\s+');
|
|
14
11
|
var lastSlash = string.lastIndexOf('/');
|
|
15
12
|
return new RegExp(string.slice(1, lastSlash), string.slice(lastSlash + 1));
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
exports.keyword = function (regexp) {
|
|
19
15
|
var newRegexp = regexp;
|
|
20
16
|
var desc = regexp.source;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _ = require('lodash');
|
|
4
|
-
|
|
5
4
|
function findTable(ast, tableName, schemaName) {
|
|
6
5
|
var realSchemaName = schemaName || 'public';
|
|
7
6
|
var table = ast.tables.find(function (t) {
|
|
@@ -10,25 +9,21 @@ function findTable(ast, tableName, schemaName) {
|
|
|
10
9
|
});
|
|
11
10
|
return table;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function findField(table, fieldName) {
|
|
15
13
|
return table.fields.find(function (_field) {
|
|
16
14
|
return _field.name === fieldName;
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
function handleIndexes(index, ast) {
|
|
21
18
|
var table = findTable(ast, index.tableName, index.schemaName);
|
|
22
19
|
table.indexes.push(index);
|
|
23
20
|
index.tableName = null;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
function pushOut(values, astProp) {
|
|
27
23
|
values.forEach(function (value) {
|
|
28
24
|
astProp.push(value);
|
|
29
25
|
});
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
function handleTable(table, ast) {
|
|
33
28
|
pushOut(table.enums, ast.enums);
|
|
34
29
|
pushOut(table.refs, ast.refs);
|
|
@@ -38,7 +33,6 @@ function handleTable(table, ast) {
|
|
|
38
33
|
table.enums = null;
|
|
39
34
|
table.refs = null;
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
function handleDefaults(dbdefault, ast) {
|
|
43
37
|
var table = findTable(ast, dbdefault.tableName, dbdefault.schemaName);
|
|
44
38
|
var field = findField(table, dbdefault.fieldName);
|
|
@@ -46,7 +40,6 @@ function handleDefaults(dbdefault, ast) {
|
|
|
46
40
|
dbdefault.tableName = null;
|
|
47
41
|
field.dbdefault = dbdefault;
|
|
48
42
|
}
|
|
49
|
-
|
|
50
43
|
function handleEnums(_enum, ast) {
|
|
51
44
|
var table = findTable(ast, _enum.tableName, _enum.schemaName);
|
|
52
45
|
var field = findField(table, _enum.fieldName);
|
|
@@ -58,23 +51,18 @@ function handleEnums(_enum, ast) {
|
|
|
58
51
|
return "'".concat(value.name, "'");
|
|
59
52
|
}).join(', ');
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
function handleTableNote(comment, ast) {
|
|
63
55
|
var schemaName = comment.schemaName;
|
|
64
56
|
if (schemaName === 'dbo') schemaName = null; // treat `dbo` as public schema
|
|
65
|
-
|
|
66
57
|
var foundTable = findTable(ast, comment.tableName, schemaName);
|
|
67
58
|
if (foundTable) foundTable.note = comment.note ? {
|
|
68
59
|
value: comment.note
|
|
69
60
|
} : null;
|
|
70
61
|
}
|
|
71
|
-
|
|
72
62
|
function handleFieldNote(comment, ast) {
|
|
73
63
|
var schemaName = comment.schemaName;
|
|
74
64
|
if (schemaName === 'dbo') schemaName = null; // treat `dbo` as public schema
|
|
75
|
-
|
|
76
65
|
var foundTable = findTable(ast, comment.tableName, schemaName);
|
|
77
|
-
|
|
78
66
|
if (foundTable) {
|
|
79
67
|
var foundField = findField(foundTable, comment.columnName);
|
|
80
68
|
if (foundField) foundField.note = comment.note ? {
|
|
@@ -82,11 +70,9 @@ function handleFieldNote(comment, ast) {
|
|
|
82
70
|
} : null;
|
|
83
71
|
}
|
|
84
72
|
}
|
|
85
|
-
|
|
86
73
|
function handleComment(comment, ast) {
|
|
87
74
|
if (comment.type === 'table') handleTableNote(comment, ast);else if (comment.type === 'column') handleFieldNote(comment, ast);
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
function handleStatement(_statements) {
|
|
91
77
|
var ast = {
|
|
92
78
|
tables: [],
|
|
@@ -94,44 +80,34 @@ function handleStatement(_statements) {
|
|
|
94
80
|
indexes: [],
|
|
95
81
|
enums: []
|
|
96
82
|
};
|
|
97
|
-
|
|
98
83
|
var statements = _.flatten(_statements);
|
|
99
|
-
|
|
100
84
|
statements.forEach(function (statement) {
|
|
101
85
|
if (!statement) return;
|
|
102
|
-
|
|
103
86
|
switch (statement.type) {
|
|
104
87
|
case 'tables':
|
|
105
88
|
handleTable(statement.value, ast);
|
|
106
89
|
break;
|
|
107
90
|
// from alter table add
|
|
108
|
-
|
|
109
91
|
case 'indexes':
|
|
110
92
|
handleIndexes(statement.value, ast);
|
|
111
93
|
break;
|
|
112
|
-
|
|
113
94
|
case 'dbdefault':
|
|
114
95
|
handleDefaults(statement.value, ast);
|
|
115
96
|
break;
|
|
116
|
-
|
|
117
97
|
case 'enums':
|
|
118
98
|
handleEnums(statement.value, ast);
|
|
119
99
|
break;
|
|
120
|
-
|
|
121
100
|
case 'comment':
|
|
122
101
|
handleComment(statement.value, ast);
|
|
123
102
|
break;
|
|
124
|
-
|
|
125
103
|
default:
|
|
126
104
|
break;
|
|
127
105
|
}
|
|
128
|
-
|
|
129
106
|
if (statement.type && ast[statement.type]) ast[statement.type].push(statement.value);
|
|
130
107
|
});
|
|
131
108
|
ast.indexes = null;
|
|
132
109
|
return ast;
|
|
133
110
|
}
|
|
134
|
-
|
|
135
111
|
module.exports = {
|
|
136
112
|
handleStatement: handleStatement
|
|
137
113
|
};
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var P = require('parsimmon');
|
|
4
|
-
|
|
5
4
|
var KP = require('../keyword_parsers');
|
|
6
|
-
|
|
7
5
|
var S = require('./statement_types');
|
|
8
|
-
|
|
9
6
|
var wss = require('../whitespaces');
|
|
10
|
-
|
|
11
7
|
var A = require('./actions');
|
|
12
|
-
|
|
13
8
|
var _require = require('../base_parsers'),
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
pIgnore = _require.pIgnore;
|
|
16
10
|
var Lang = P.createLanguage({
|
|
17
11
|
Statements: function Statements(r) {
|
|
18
12
|
return wss.then(r.Seperator).then(P.sepBy(r.StatementTypes, r.Seperator)).skip(r.Seperator).map(A.handleStatement);
|