@dbml/core 2.2.0 → 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 +15 -4
- package/lib/export/JsonExporter.js +1 -3
- package/lib/export/ModelExporter.js +1 -3
- package/lib/export/MysqlExporter.js +50 -42
- package/lib/export/PostgresExporter.js +64 -49
- package/lib/export/SqlServerExporter.js +52 -46
- package/lib/model_structure/database.js +73 -28
- package/lib/model_structure/dbState.js +1 -3
- package/lib/model_structure/element.js +13 -13
- package/lib/model_structure/endpoint.js +18 -14
- package/lib/model_structure/enum.js +18 -14
- package/lib/model_structure/enumValue.js +16 -12
- package/lib/model_structure/field.js +47 -13
- package/lib/model_structure/indexColumn.js +16 -12
- package/lib/model_structure/indexes.js +18 -14
- package/lib/model_structure/ref.js +19 -16
- package/lib/model_structure/schema.js +24 -36
- package/lib/model_structure/table.js +19 -15
- package/lib/model_structure/tableGroup.js +18 -14
- package/lib/model_structure/utils.js +5 -0
- package/lib/parse/Parser.js +2 -4
- package/lib/parse/buildParser.js +1 -3
- package/lib/parse/dbml/parser.pegjs +64 -20
- package/lib/parse/dbmlParser.js +1401 -899
- package/lib/parse/mssql/constraint_definition/actions.js +2 -2
- package/lib/parse/mssql/fk_definition/actions.js +10 -3
- package/lib/parse/mssql/keyword_parsers.js +0 -1
- 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 +12 -10
- package/lib/parse/mssql/utils.js +16 -1
- package/lib/parse/mysql/parser.pegjs +57 -34
- package/lib/parse/mysqlParser.js +270 -218
- package/lib/parse/postgresParser.js +12 -10
- package/lib/parse/postgresql/Base_rules.pegjs +45 -10
- 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/lib/parse/schemarbParser.js +3 -3
- package/package.json +5 -3
- package/types/export/ModelExporter.d.ts +5 -0
- package/types/export/index.d.ts +5 -0
- package/types/import/index.d.ts +5 -0
- package/types/index.d.ts +5 -0
- package/types/model_structure/database.d.ts +195 -0
- package/types/model_structure/dbState.d.ts +14 -0
- package/types/model_structure/element.d.ts +21 -0
- package/types/model_structure/endpoint.d.ts +55 -0
- package/types/model_structure/enum.d.ts +67 -0
- package/types/model_structure/enumValue.d.ts +39 -0
- package/types/model_structure/field.d.ts +77 -0
- package/types/model_structure/indexColumn.d.ts +37 -0
- package/types/model_structure/indexes.d.ts +74 -0
- package/types/model_structure/ref.d.ts +66 -0
- package/types/model_structure/schema.d.ts +188 -0
- package/types/model_structure/table.d.ts +118 -0
- package/types/model_structure/tableGroup.d.ts +54 -0
- package/types/parse/Parser.d.ts +11 -0
- package/lib/export/Exporter.js +0 -80
- package/lib/export/SchemaExporter.js +0 -99
- package/lib/parse/dbml/multiline_content.txt +0 -7
- package/lib/parse/dbml/multiline_string.pegjs +0 -17
- package/lib/parse/dbml/parser1.json +0 -219
- package/lib/parse/dbml/parser1.pegjs +0 -702
- package/lib/parse/dbml/parser1_content.txt +0 -29
- package/lib/parse/dbml/test_multiline.js +0 -53
- package/lib/parse/dbml/test_parser1.js +0 -16
- package/lib/parse/mssql/base_utils.js +0 -28
- package/lib/parse/mssql/composite_parsers.js +0 -109
- package/lib/parse/mssql/statement_types/alter_table/actions.js +0 -29
- package/lib/parse/mssql/statement_types/alter_table/add/actions.js +0 -8
- package/lib/parse/mssql/statement_types/alter_table/add/index.js +0 -58
- package/lib/parse/mssql/statement_types/alter_table/index.js +0 -32
- package/lib/parse/mssql/statement_types/create_index/actions.js +0 -25
- package/lib/parse/mssql/statement_types/create_index/index.js +0 -50
- package/lib/parse/mssql/statement_types/create_table/actions.js +0 -95
- package/lib/parse/mssql/statement_types/create_table/index.js +0 -50
- package/lib/parse/mssql/statement_types/index.js +0 -13
- package/lib/schema/element.js +0 -84
- package/lib/schema/endpoint.js +0 -102
- package/lib/schema/enum.js +0 -102
- package/lib/schema/enumValue.js +0 -70
- package/lib/schema/field.js +0 -104
- package/lib/schema/indexes.js +0 -74
- package/lib/schema/ref.js +0 -93
- package/lib/schema/schema.js +0 -245
- package/lib/schema/table.js +0 -163
- package/lib/schema/tableGroup.js +0 -93
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
|
|
5
|
-
var pegjsRequire = require('pegjs-require-import');
|
|
6
|
-
|
|
7
|
-
var parser = pegjsRequire('./multiline_string.pegjs', {
|
|
8
|
-
format: 'commonjs',
|
|
9
|
-
dependencies: {
|
|
10
|
-
_: 'lodash'
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
var content = fs.readFileSync('src/parse/dbml/multiline_content.txt', 'utf-8');
|
|
14
|
-
var rawStr = parser.parse(content);
|
|
15
|
-
console.log(rawStr);
|
|
16
|
-
rawStr = rawStr.replace(/\\[\n|\r\n]?/g, '');
|
|
17
|
-
var lines = rawStr.split(/[\n|\r\n]/);
|
|
18
|
-
console.log(lines);
|
|
19
|
-
|
|
20
|
-
var leadingSpaces = function leadingSpaces(str) {
|
|
21
|
-
var i = 0;
|
|
22
|
-
|
|
23
|
-
while (i < str.length && str[i] === ' ') {
|
|
24
|
-
i += 1;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return i;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
var minLeadingSpaces = lines.filter(function (line) {
|
|
31
|
-
return line.replace(/\s+/g, '');
|
|
32
|
-
}).reduce(function (acc, cur) {
|
|
33
|
-
return Math.min(acc, leadingSpaces(cur));
|
|
34
|
-
}, Number.MAX_SAFE_INTEGER);
|
|
35
|
-
lines = lines.map(function (line) {
|
|
36
|
-
return line ? line.slice(minLeadingSpaces) : line;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
var countLeadingEmptyLine = function countLeadingEmptyLine(lines) {
|
|
40
|
-
var i = 0;
|
|
41
|
-
|
|
42
|
-
while (i < lines.length && !lines[i].replace(/\s+/g, '')) {
|
|
43
|
-
i += 1;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return i;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
lines.splice(0, countLeadingEmptyLine(lines));
|
|
50
|
-
lines.splice(lines.length - countLeadingEmptyLine(lines.slice().reverse()));
|
|
51
|
-
var finalStr = lines.join('\n');
|
|
52
|
-
console.log('==========================================================');
|
|
53
|
-
console.log(finalStr);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
|
|
5
|
-
var pegjsRequire = require('pegjs-require-import');
|
|
6
|
-
|
|
7
|
-
var parser = pegjsRequire('./parser.pegjs', {
|
|
8
|
-
format: 'commonjs',
|
|
9
|
-
dependencies: {
|
|
10
|
-
_: 'lodash'
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
var content = fs.readFileSync('src/parse/dbml/parser1_content.txt', 'utf-8');
|
|
14
|
-
var res = parser.parse(content);
|
|
15
|
-
fs.writeFileSync('src/parse/dbml/parser1.json', JSON.stringify(res, null, 2));
|
|
16
|
-
console.log(res);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var P = require('parsimmon');
|
|
4
|
-
|
|
5
|
-
var wss = require('./whitespaces');
|
|
6
|
-
|
|
7
|
-
exports.word = function (string) {
|
|
8
|
-
return P.string(string).skip(wss).desc("\"".concat(string, "\""));
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function replaceWhitespaceWithRegexp(regexp) {
|
|
12
|
-
var string = String(regexp);
|
|
13
|
-
string = string.replace(/[\s]+/g, '[^\\S\\r]+');
|
|
14
|
-
var lastSlash = string.lastIndexOf('/');
|
|
15
|
-
return new RegExp(string.slice(1, lastSlash), string.slice(lastSlash + 1));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.keyword = function (regexp) {
|
|
19
|
-
var multiword = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
20
|
-
var newRegexp = regexp;
|
|
21
|
-
var desc = regexp.source;
|
|
22
|
-
|
|
23
|
-
if (multiword) {
|
|
24
|
-
newRegexp = replaceWhitespaceWithRegexp(regexp);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return P.regexp(newRegexp).skip(wss).desc("\"".concat(desc, "\""));
|
|
28
|
-
};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var P = require('parsimmon');
|
|
4
|
-
|
|
5
|
-
var _require = require('./utils'),
|
|
6
|
-
makeList = _require.makeList,
|
|
7
|
-
streamline = _require.streamline;
|
|
8
|
-
|
|
9
|
-
var BP = require('./base_parsers');
|
|
10
|
-
|
|
11
|
-
var wss = require('./whitespaces');
|
|
12
|
-
|
|
13
|
-
var Lang = P.createLanguage({
|
|
14
|
-
pIgnore: function pIgnore() {
|
|
15
|
-
return P.regex(/[^;]+/);
|
|
16
|
-
},
|
|
17
|
-
pColumnNames: function pColumnNames(r) {
|
|
18
|
-
return makeList(P.seq(r.pIdentifier, r.pKeywordAscOrDesc.fallback(null)).map(function (value) {
|
|
19
|
-
return value[0];
|
|
20
|
-
})).desc('list of column names');
|
|
21
|
-
},
|
|
22
|
-
pDotDelimitedName: function pDotDelimitedName(r) {
|
|
23
|
-
return P.sepBy1(r.pIdentifier, P.string('.')).desc('dot delimited identifier');
|
|
24
|
-
},
|
|
25
|
-
pOptionList: function pOptionList(r) {
|
|
26
|
-
return makeList(r.pOption);
|
|
27
|
-
},
|
|
28
|
-
pOption: function pOption(r) {
|
|
29
|
-
return P.seq(r.pIdentifier, BP.Equal, P.seq(P.alt(r.pIdentifier, r.pString).many(), P.alt(r.pOptionList, makeList(r.pIdentifier.many())).fallback(null))).desc('option');
|
|
30
|
-
},
|
|
31
|
-
pComparsionOp: function pComparsionOp() {
|
|
32
|
-
return P.regex(/IS|IS[^\S\r\n]+NOT|=|<>|!=|>|>=|!>|<|<=|!</i).skip(wss).desc('comparsion operator');
|
|
33
|
-
},
|
|
34
|
-
// SQL SERVER do not support boolean literal
|
|
35
|
-
pConst: function pConst(r) {
|
|
36
|
-
return P.alt(r.pString, r.pUnicode, r.pBinary, r.pScience, r.pMoney, r.pSigned, r.pNumber).desc('constant');
|
|
37
|
-
},
|
|
38
|
-
pFunction: function pFunction(r) {
|
|
39
|
-
return P.seq(r.pIdentifier, makeList(r.pFunctionParam, true)).map(function (value) {
|
|
40
|
-
return "".concat(value[0], "(").concat(value[1].join(','), ")");
|
|
41
|
-
}).thru(streamline('function')).desc('function constant');
|
|
42
|
-
},
|
|
43
|
-
pFunctionParam: function pFunctionParam(r) {
|
|
44
|
-
return P.alt(r.pNumber, r.pIdentifier).desc('identifier or number paremeter');
|
|
45
|
-
},
|
|
46
|
-
pMoney: function pMoney(r) {
|
|
47
|
-
return P.seq(P.regexp(/[+-]\$/), r.pNumber).thru(streamline('money')).desc('money constant');
|
|
48
|
-
},
|
|
49
|
-
pSigned: function pSigned(r) {
|
|
50
|
-
return P.seq(P.regexp(/[+-]/), r.pNumber).thru(streamline('signed')).desc('signed constant');
|
|
51
|
-
},
|
|
52
|
-
pUnicode: function pUnicode(r) {
|
|
53
|
-
return P.seq(P.string('N'), r.pString).thru(streamline('unicode')).desc('unicode constant');
|
|
54
|
-
},
|
|
55
|
-
pString: function pString() {
|
|
56
|
-
return P.regexp(/'[^']*'/).thru(streamline('string')).map(function (value) {
|
|
57
|
-
var stringLiteral = value.value;
|
|
58
|
-
value.value = stringLiteral.slice(1, stringLiteral.length - 1);
|
|
59
|
-
return value;
|
|
60
|
-
}).desc('string constant');
|
|
61
|
-
},
|
|
62
|
-
pNumberList: function pNumberList(r) {
|
|
63
|
-
return makeList(r.pNumber).desc('list of number');
|
|
64
|
-
},
|
|
65
|
-
pNumber: function pNumber() {
|
|
66
|
-
return P.regexp(/[0-9]+(\.[0-9]+)?/).map(Number).thru(streamline('number')).desc('number constant');
|
|
67
|
-
},
|
|
68
|
-
pBinary: function pBinary() {
|
|
69
|
-
return P.regexp(/0x[A-F0-9]*/).thru(streamline('binary')).desc('binary constant');
|
|
70
|
-
},
|
|
71
|
-
pScience: function pScience() {
|
|
72
|
-
return P.regexp(/[+-]+[0-9]+(\.[0-9E]+)?/).thru(streamline('science')).desc('science constant');
|
|
73
|
-
},
|
|
74
|
-
pIdentifier: function pIdentifier(r) {
|
|
75
|
-
return P.alt(r.pRegularIdentifier, r.pDelimitedIdentifier).skip(wss).desc('identifier');
|
|
76
|
-
},
|
|
77
|
-
pDelimitedIdentifier: function pDelimitedIdentifier(r) {
|
|
78
|
-
return P.alt(r.pDQDelimitedIdentifier, r.pBracketDelimitedIdentifier).skip(wss).desc('delimited identifier');
|
|
79
|
-
},
|
|
80
|
-
pRegularIdentifier: function pRegularIdentifier() {
|
|
81
|
-
return P.regexp(/^[\w@#][\w@#$]*/).skip(wss);
|
|
82
|
-
},
|
|
83
|
-
pDQDelimitedIdentifier: function pDQDelimitedIdentifier() {
|
|
84
|
-
return P.seq(P.string('"'), P.regexp(/[^"]*/), P.string('"')).map(function (value) {
|
|
85
|
-
return value[1];
|
|
86
|
-
}).skip(wss);
|
|
87
|
-
},
|
|
88
|
-
pBracketDelimitedIdentifier: function pBracketDelimitedIdentifier() {
|
|
89
|
-
return P.seq(P.string('['), P.regexp(/[^\]]*/), P.string(']')).map(function (value) {
|
|
90
|
-
return value[1];
|
|
91
|
-
}).skip(wss);
|
|
92
|
-
},
|
|
93
|
-
pKeywordPKOrUnique: function pKeywordPKOrUnique() {
|
|
94
|
-
return P.alt(BP.KeywordPrimaryKey.result({
|
|
95
|
-
type: 'pk',
|
|
96
|
-
value: true
|
|
97
|
-
}), BP.KeywordUnique.result({
|
|
98
|
-
type: 'unique',
|
|
99
|
-
value: true
|
|
100
|
-
}));
|
|
101
|
-
},
|
|
102
|
-
pKeywordClusteredOrNon: function pKeywordClusteredOrNon() {
|
|
103
|
-
return P.alt(BP.KeywordClustered, BP.KeywordNonclustered);
|
|
104
|
-
},
|
|
105
|
-
pKeywordAscOrDesc: function pKeywordAscOrDesc() {
|
|
106
|
-
return P.alt(BP.KeywordAsc, BP.KeywordDesc);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
module.exports = Lang;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
function handleRef(tableName, result) {
|
|
6
|
-
var endpointWithNoTableName = result.value.endpoints.find(function (ele) {
|
|
7
|
-
return !ele.tableName;
|
|
8
|
-
});
|
|
9
|
-
endpointWithNoTableName.tableName = _.last(tableName);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function handleAlterTableResult(_keyword, tableName, result) {
|
|
13
|
-
if (!result) return null;
|
|
14
|
-
|
|
15
|
-
switch (result.type) {
|
|
16
|
-
case 'refs':
|
|
17
|
-
handleRef(tableName, result);
|
|
18
|
-
break;
|
|
19
|
-
|
|
20
|
-
default:
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = {
|
|
28
|
-
handleAlterTableResult: handleAlterTableResult
|
|
29
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var P = require('parsimmon');
|
|
4
|
-
|
|
5
|
-
var BP = require('../../../base_parsers');
|
|
6
|
-
|
|
7
|
-
var _require = require('../../../composite_parsers'),
|
|
8
|
-
pIdentifier = _require.pIdentifier;
|
|
9
|
-
|
|
10
|
-
var _require2 = require('../../../utils'),
|
|
11
|
-
makeNode = _require2.makeNode,
|
|
12
|
-
makeList = _require2.makeList;
|
|
13
|
-
|
|
14
|
-
var A = require('./actions');
|
|
15
|
-
|
|
16
|
-
var _require3 = require('../../../fk_definition'),
|
|
17
|
-
pTableConstraintFK = _require3.pTableConstraintFK;
|
|
18
|
-
|
|
19
|
-
var _require4 = require('../../../index_definition'),
|
|
20
|
-
pTableConstraintIndex = _require4.pTableConstraintIndex;
|
|
21
|
-
|
|
22
|
-
var _require5 = require('../../../constraint_definition'),
|
|
23
|
-
pConstraintCheck = _require5.pConstraintCheck,
|
|
24
|
-
pConstExpr = _require5.pConstExpr,
|
|
25
|
-
pConstraintName = _require5.pConstraintName;
|
|
26
|
-
|
|
27
|
-
var _require6 = require('../../../column_definition'),
|
|
28
|
-
pColumnsDefinition = _require6.pColumnsDefinition;
|
|
29
|
-
|
|
30
|
-
var Lang = P.createLanguage({
|
|
31
|
-
AddAction: function AddAction(r) {
|
|
32
|
-
return P.seq(BP.KeywordAdd, r.AddOption).map(function (value) {
|
|
33
|
-
return value[1];
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
AddOption: function AddOption(r) {
|
|
37
|
-
return P.alt(r.AddConstraint, pColumnsDefinition.result(null), r.IgnoredAddSystemTimeOption.result(null));
|
|
38
|
-
},
|
|
39
|
-
IgnoredAddSystemTimeOption: function IgnoredAddSystemTimeOption() {
|
|
40
|
-
return P.alt(pIdentifier, P.regexp(/[(),]/)).many();
|
|
41
|
-
},
|
|
42
|
-
AddConstraint: function AddConstraint(r) {
|
|
43
|
-
return P.seqMap(pConstraintName.fallback(null), r.AddConstraintOption, A.makeTableConstraint).thru(makeNode());
|
|
44
|
-
},
|
|
45
|
-
AddConstraintOption: function AddConstraintOption(r) {
|
|
46
|
-
return P.alt(pTableConstraintFK, r.IgnoredAddConstraintOption);
|
|
47
|
-
},
|
|
48
|
-
IgnoredAddConstraintOption: function IgnoredAddConstraintOption(r) {
|
|
49
|
-
return P.alt(pTableConstraintIndex, pConstraintCheck, r.AddConstraintDefault, r.AddConstraintConnection);
|
|
50
|
-
},
|
|
51
|
-
AddConstraintDefault: function AddConstraintDefault() {
|
|
52
|
-
return P.seq(BP.KeywordDefault, pConstExpr, BP.KeywordFor, pIdentifier, BP.KeywordWithValues.fallback(null));
|
|
53
|
-
},
|
|
54
|
-
AddConstraintConnection: function AddConstraintConnection() {
|
|
55
|
-
return P.seq(BP.KeywordConnection, makeList(P.seq(pIdentifier, BP.KeywordTo, pIdentifier)));
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
module.exports = Lang.AddAction;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var P = require('parsimmon');
|
|
4
|
-
|
|
5
|
-
var BP = require('../../base_parsers');
|
|
6
|
-
|
|
7
|
-
var _require = require('../../composite_parsers'),
|
|
8
|
-
pDotDelimitedName = _require.pDotDelimitedName,
|
|
9
|
-
pIgnore = _require.pIgnore;
|
|
10
|
-
|
|
11
|
-
var A = require('./actions');
|
|
12
|
-
|
|
13
|
-
var pAddAction = require('./add');
|
|
14
|
-
|
|
15
|
-
var Lang = P.createLanguage({
|
|
16
|
-
AlterTable: function AlterTable(r) {
|
|
17
|
-
return P.seqMap(r.AlterTableKeywords, pDotDelimitedName, r.AlterTableActions, A.handleAlterTableResult);
|
|
18
|
-
},
|
|
19
|
-
AlterTableActions: function AlterTableActions(r) {
|
|
20
|
-
return P.alt(pAddAction, r.IgnoredAlterTableActions);
|
|
21
|
-
},
|
|
22
|
-
AlterTableKeywords: function AlterTableKeywords() {
|
|
23
|
-
return P.seq(BP.KeywordAlter, BP.KeywordTable);
|
|
24
|
-
},
|
|
25
|
-
IgnoredAlterTableActions: function IgnoredAlterTableActions(r) {
|
|
26
|
-
return P.seq(r.IgnoredAlterTableActionKeywords, pIgnore).result(null);
|
|
27
|
-
},
|
|
28
|
-
IgnoredAlterTableActionKeywords: function IgnoredAlterTableActionKeywords() {
|
|
29
|
-
return P.alt(BP.KeywordWith, BP.KeywordAlterColumn, BP.KeywordDrop, BP.KeywordEnable, BP.KeywordDisable, BP.KeywordCheck, BP.KeywordSwitch, BP.KeywordSet, BP.KeywordRebuild);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
module.exports = Lang.AlterTable;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function makeIndex(_create, isUnique, _clustered, _index, indexName, _on, tableName, columnNames) {
|
|
4
|
-
var columns = [];
|
|
5
|
-
columnNames.forEach(function (columnName) {
|
|
6
|
-
columns.push({
|
|
7
|
-
value: columnName,
|
|
8
|
-
type: 'column'
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
return {
|
|
12
|
-
type: 'indexes',
|
|
13
|
-
value: {
|
|
14
|
-
name: indexName,
|
|
15
|
-
type: 'btree',
|
|
16
|
-
unique: isUnique ? true : null,
|
|
17
|
-
tableName: tableName[tableName.length - 1],
|
|
18
|
-
columns: columns
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
makeIndex: makeIndex
|
|
25
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var P = require('parsimmon');
|
|
4
|
-
|
|
5
|
-
var BP = require('../../base_parsers');
|
|
6
|
-
|
|
7
|
-
var _require = require('../../composite_parsers'),
|
|
8
|
-
pIdentifier = _require.pIdentifier,
|
|
9
|
-
pKeywordClusteredOrNon = _require.pKeywordClusteredOrNon,
|
|
10
|
-
pConst = _require.pConst,
|
|
11
|
-
pColumnNames = _require.pColumnNames,
|
|
12
|
-
pDotDelimitedName = _require.pDotDelimitedName,
|
|
13
|
-
pComparsionOp = _require.pComparsionOp;
|
|
14
|
-
|
|
15
|
-
var _require2 = require('../../utils'),
|
|
16
|
-
makeNode = _require2.makeNode,
|
|
17
|
-
makeList = _require2.makeList;
|
|
18
|
-
|
|
19
|
-
var A = require('./actions');
|
|
20
|
-
|
|
21
|
-
var _require3 = require('../../index_definition'),
|
|
22
|
-
pIgnoredIndexOption = _require3.pIgnoredIndexOption;
|
|
23
|
-
|
|
24
|
-
var Lang = P.createLanguage({
|
|
25
|
-
CreateIndex: function CreateIndex(r) {
|
|
26
|
-
return P.seqMap(BP.KeywordCreate, BP.KeywordUnique.fallback(null), pKeywordClusteredOrNon.fallback(null), BP.KeywordIndex, pIdentifier, BP.KeywordOn, pDotDelimitedName, pColumnNames, A.makeIndex).thru(makeNode()).skip(r.IgnoredCreateIndexOptions);
|
|
27
|
-
},
|
|
28
|
-
IgnoredCreateIndexOptions: function IgnoredCreateIndexOptions(r) {
|
|
29
|
-
return P.alt(pIgnoredIndexOption, r.IncludeIndexOption, r.WhereIndexOption).many();
|
|
30
|
-
},
|
|
31
|
-
IncludeIndexOption: function IncludeIndexOption() {
|
|
32
|
-
return P.seq(BP.KeywordInclude, pColumnNames);
|
|
33
|
-
},
|
|
34
|
-
WhereIndexOption: function WhereIndexOption(r) {
|
|
35
|
-
return P.seq(BP.KeywordWhere, r.FilterPredicate);
|
|
36
|
-
},
|
|
37
|
-
FilterPredicate: function FilterPredicate(r) {
|
|
38
|
-
return P.seq(r.Conjunct, P.seq(BP.LogicalOpAnd, r.Conjunct).fallback(null));
|
|
39
|
-
},
|
|
40
|
-
Conjunct: function Conjunct(r) {
|
|
41
|
-
return P.alt(r.Disjunct, r.Comparsion);
|
|
42
|
-
},
|
|
43
|
-
Disjunct: function Disjunct() {
|
|
44
|
-
return P.seq(pIdentifier, BP.KeywordIn, makeList(pConst));
|
|
45
|
-
},
|
|
46
|
-
Comparsion: function Comparsion() {
|
|
47
|
-
return P.seq(pIdentifier, pComparsionOp, pConst);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
module.exports = Lang.CreateIndex;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
|
|
9
|
-
var _ = require('lodash');
|
|
10
|
-
|
|
11
|
-
function createRefFromInlineRef(linesRefs, inlineRefs, fieldName, tableName) {
|
|
12
|
-
if (!inlineRefs || inlineRefs.length === 0) return;
|
|
13
|
-
var newRef = {};
|
|
14
|
-
var inlineRef = inlineRefs[0];
|
|
15
|
-
newRef.onUpdate = inlineRef.onUpdate;
|
|
16
|
-
newRef.onDelete = inlineRef.onDelete;
|
|
17
|
-
newRef.endpoints = [];
|
|
18
|
-
newRef.endpoints.push({
|
|
19
|
-
tableName: tableName,
|
|
20
|
-
fieldNames: [fieldName],
|
|
21
|
-
relation: '*'
|
|
22
|
-
});
|
|
23
|
-
newRef.endpoints.push(inlineRef.endpoint);
|
|
24
|
-
linesRefs.push(newRef);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function pushOutEnum(linesEnums, fieldValue, tableName) {
|
|
28
|
-
if (fieldValue.enums) {
|
|
29
|
-
var _enum = fieldValue.enums;
|
|
30
|
-
var fieldType = fieldValue.type;
|
|
31
|
-
_enum.name = "".concat(tableName, "_").concat(fieldValue.enums.name);
|
|
32
|
-
fieldType.type_name = _enum.name;
|
|
33
|
-
fieldType.args = _enum.values.map(function (value) {
|
|
34
|
-
return "'".concat(value.name, "'");
|
|
35
|
-
}).join(', ');
|
|
36
|
-
linesEnums.push(_enum);
|
|
37
|
-
fieldValue.enums = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function pushOutIndex(linesIndexes, fieldValue) {
|
|
42
|
-
if (fieldValue.indexes) {
|
|
43
|
-
fieldValue.indexes.columns.push({
|
|
44
|
-
value: fieldValue.name,
|
|
45
|
-
type: 'column'
|
|
46
|
-
});
|
|
47
|
-
linesIndexes.push(fieldValue.indexes);
|
|
48
|
-
fieldValue.indexes = null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getLinesValue(lines, tableName) {
|
|
53
|
-
var value = {
|
|
54
|
-
fields: [],
|
|
55
|
-
enums: [],
|
|
56
|
-
refs: [],
|
|
57
|
-
indexes: []
|
|
58
|
-
};
|
|
59
|
-
lines.forEach(function (line) {
|
|
60
|
-
if (line && value[line.type]) {
|
|
61
|
-
if (line.type === 'fields') {
|
|
62
|
-
pushOutEnum(value.enums, line.value, tableName);
|
|
63
|
-
pushOutIndex(value.indexes, line.value);
|
|
64
|
-
createRefFromInlineRef(value.refs, line.value.inline_refs, line.value.name, tableName);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (line.type === 'refs') {
|
|
68
|
-
var ref = line.value;
|
|
69
|
-
ref.endpoints[0].tableName = tableName;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
value[line.type].push(line.value);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return {
|
|
76
|
-
type: 'lines',
|
|
77
|
-
value: value
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function makeTable(_keyword, tableName, _keyword2, lines) {
|
|
82
|
-
var linesValue = getLinesValue(lines, _.last(tableName));
|
|
83
|
-
return {
|
|
84
|
-
type: 'tables',
|
|
85
|
-
value: _objectSpread({
|
|
86
|
-
name: _.last(tableName)
|
|
87
|
-
}, linesValue.value, {
|
|
88
|
-
schemaName: tableName.length > 1 ? tableName[tableName.length - 2] : null
|
|
89
|
-
})
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
module.exports = {
|
|
94
|
-
makeTable: makeTable
|
|
95
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var P = require('parsimmon');
|
|
4
|
-
|
|
5
|
-
var BP = require('../../base_parsers');
|
|
6
|
-
|
|
7
|
-
var _require = require('../../composite_parsers'),
|
|
8
|
-
pIdentifier = _require.pIdentifier,
|
|
9
|
-
pDotDelimitedName = _require.pDotDelimitedName;
|
|
10
|
-
|
|
11
|
-
var _require2 = require('../../utils'),
|
|
12
|
-
makeNode = _require2.makeNode,
|
|
13
|
-
makeList = _require2.makeList;
|
|
14
|
-
|
|
15
|
-
var _require3 = require('../../constraint_definition'),
|
|
16
|
-
pTableConstraint = _require3.pTableConstraint;
|
|
17
|
-
|
|
18
|
-
var _require4 = require('../../index_definition'),
|
|
19
|
-
pTableIndex = _require4.pTableIndex,
|
|
20
|
-
pIgnoredIndexOption = _require4.pIgnoredIndexOption;
|
|
21
|
-
|
|
22
|
-
var _require5 = require('../../column_definition'),
|
|
23
|
-
pColumnsDefinition = _require5.pColumnsDefinition;
|
|
24
|
-
|
|
25
|
-
var A = require('./actions');
|
|
26
|
-
|
|
27
|
-
var Lang = P.createLanguage({
|
|
28
|
-
CreateTable: function CreateTable(r) {
|
|
29
|
-
return P.seqMap(r.CreateTableKeywords, pDotDelimitedName, r.AsFileTableKeywords.fallback(null), makeList(r.Line), A.makeTable).thru(makeNode()).skip(r.IgnoredTableOptions);
|
|
30
|
-
},
|
|
31
|
-
CreateTableKeywords: function CreateTableKeywords() {
|
|
32
|
-
return P.seq(BP.KeywordCreate, BP.KeywordTable);
|
|
33
|
-
},
|
|
34
|
-
AsFileTableKeywords: function AsFileTableKeywords() {
|
|
35
|
-
return P.seq(BP.KeywordAs, BP.KeywordFileTable);
|
|
36
|
-
},
|
|
37
|
-
Line: function Line(r) {
|
|
38
|
-
return P.alt(r.SystemTimeTableOption, pTableConstraint, pTableIndex, pColumnsDefinition);
|
|
39
|
-
},
|
|
40
|
-
SystemTimeTableOption: function SystemTimeTableOption() {
|
|
41
|
-
return P.seq(BP.KeywordPeriodForST, makeList(pIdentifier)).result(null);
|
|
42
|
-
},
|
|
43
|
-
IgnoredTableOptions: function IgnoredTableOptions(r) {
|
|
44
|
-
return P.alt(pIgnoredIndexOption, r.TextImageTableOption).many();
|
|
45
|
-
},
|
|
46
|
-
TextImageTableOption: function TextImageTableOption() {
|
|
47
|
-
return P.seq(BP.KeywordTextImage_On, pIdentifier);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
module.exports = Lang.CreateTable;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var pAlterTable = require('./alter_table');
|
|
4
|
-
|
|
5
|
-
var pCreateIndex = require('./create_index/index');
|
|
6
|
-
|
|
7
|
-
var pCreateTable = require('./create_table');
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
pAlterTable: pAlterTable,
|
|
11
|
-
pCreateIndex: pCreateIndex,
|
|
12
|
-
pCreateTable: pCreateTable
|
|
13
|
-
};
|
package/lib/schema/element.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
9
|
-
|
|
10
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
11
|
-
|
|
12
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
13
|
-
|
|
14
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
-
|
|
16
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
17
|
-
|
|
18
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
-
|
|
20
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
21
|
-
|
|
22
|
-
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
23
|
-
|
|
24
|
-
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
25
|
-
|
|
26
|
-
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
27
|
-
|
|
28
|
-
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
29
|
-
|
|
30
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
-
|
|
32
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
33
|
-
|
|
34
|
-
var ElementError =
|
|
35
|
-
/*#__PURE__*/
|
|
36
|
-
function (_Error) {
|
|
37
|
-
_inherits(ElementError, _Error);
|
|
38
|
-
|
|
39
|
-
function ElementError(message) {
|
|
40
|
-
var _this;
|
|
41
|
-
|
|
42
|
-
var location = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
43
|
-
start: {
|
|
44
|
-
line: 1,
|
|
45
|
-
column: 1
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
_classCallCheck(this, ElementError);
|
|
50
|
-
|
|
51
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(ElementError).call(this, message));
|
|
52
|
-
_this.location = location;
|
|
53
|
-
return _this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return ElementError;
|
|
57
|
-
}(_wrapNativeSuper(Error));
|
|
58
|
-
|
|
59
|
-
var Element =
|
|
60
|
-
/*#__PURE__*/
|
|
61
|
-
function () {
|
|
62
|
-
function Element(token) {
|
|
63
|
-
_classCallCheck(this, Element);
|
|
64
|
-
|
|
65
|
-
this.token = token;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
_createClass(Element, [{
|
|
69
|
-
key: "bind",
|
|
70
|
-
value: function bind(selection) {
|
|
71
|
-
this.selection = selection;
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: "error",
|
|
75
|
-
value: function error(message) {
|
|
76
|
-
throw new ElementError(message, this.token);
|
|
77
|
-
}
|
|
78
|
-
}]);
|
|
79
|
-
|
|
80
|
-
return Element;
|
|
81
|
-
}();
|
|
82
|
-
|
|
83
|
-
var _default = Element;
|
|
84
|
-
exports["default"] = _default;
|