@dbml/core 2.3.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 +17 -9
- 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 +12 -2
- package/lib/parse/mssql/statements/actions.js +37 -6
- package/lib/parse/mssql/statements/index.js +1 -1
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +11 -5
- 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/create_index/actions.js +6 -1
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +12 -10
- package/lib/parse/mssql/statements/statement_types/index.js +4 -1
- package/lib/parse/mssql/utils.js +16 -1
- package/lib/parse/mysql/parser.pegjs +66 -40
- package/lib/parse/mysqlParser.js +534 -359
- package/lib/parse/postgresParser.js +15 -13
- package/lib/parse/postgresql/Base_rules.pegjs +45 -10
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +49 -4
- package/lib/parse/postgresql/Commands/Comment.pegjs +18 -6
- 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/Commands/Ignore_syntax.pegjs +10 -1
- package/lib/parse/postgresql/InitializerUtils.pegjs +14 -2
- package/lib/parse/postgresql/Keywords.pegjs +5 -1
- package/lib/parse/postgresql/parser.pegjs +22 -8
- package/lib/parse/schemarbParser.js +3 -3
- package/package.json +2 -2
|
@@ -9,6 +9,8 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
|
|
12
|
+
var _config = require("../model_structure/config");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -17,9 +19,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
17
19
|
|
|
18
20
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
19
21
|
|
|
20
|
-
var DbmlExporter =
|
|
21
|
-
/*#__PURE__*/
|
|
22
|
-
function () {
|
|
22
|
+
var DbmlExporter = /*#__PURE__*/function () {
|
|
23
23
|
function DbmlExporter() {
|
|
24
24
|
_classCallCheck(this, DbmlExporter);
|
|
25
25
|
}
|
|
@@ -29,6 +29,11 @@ function () {
|
|
|
29
29
|
value: function hasWhiteSpace(str) {
|
|
30
30
|
return /\s/g.test(str);
|
|
31
31
|
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "hasSquareBracket",
|
|
34
|
+
value: function hasSquareBracket(str) {
|
|
35
|
+
return /\[|\]/.test(str);
|
|
36
|
+
}
|
|
32
37
|
}, {
|
|
33
38
|
key: "isExpression",
|
|
34
39
|
value: function isExpression(str) {
|
|
@@ -52,7 +57,13 @@ function () {
|
|
|
52
57
|
var table = model.tables[tableId];
|
|
53
58
|
var lines = table.fieldIds.map(function (fieldId) {
|
|
54
59
|
var field = model.fields[fieldId];
|
|
55
|
-
var
|
|
60
|
+
var schemaName = '';
|
|
61
|
+
|
|
62
|
+
if (field.type.schemaName && field.type.schemaName !== _config.DEFAULT_SCHEMA_NAME) {
|
|
63
|
+
schemaName = DbmlExporter.hasWhiteSpace(field.type.schemaName) ? "\"".concat(field.type.schemaName, "\".") : "".concat(field.type.schemaName, ".");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var line = "\"".concat(field.name, "\" ").concat(schemaName).concat(DbmlExporter.hasWhiteSpace(field.type.type_name) || DbmlExporter.hasSquareBracket(field.type.type_name) ? "\"".concat(field.type.type_name, "\"") : field.type.type_name);
|
|
56
67
|
var constraints = [];
|
|
57
68
|
|
|
58
69
|
if (field.unique) {
|
|
@@ -182,10 +193,6 @@ function () {
|
|
|
182
193
|
settingStr += "headerColor: ".concat(table.headerColor).concat(settingSep);
|
|
183
194
|
}
|
|
184
195
|
|
|
185
|
-
if (table.note) {
|
|
186
|
-
settingStr += "note: '".concat(table.note, "'").concat(settingSep);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
196
|
if (settingStr.endsWith(', ')) {
|
|
190
197
|
settingStr = settingStr.replace(/,\s$/, '');
|
|
191
198
|
}
|
|
@@ -212,9 +219,10 @@ function () {
|
|
|
212
219
|
}).join('\n'), "\n}");
|
|
213
220
|
}
|
|
214
221
|
|
|
222
|
+
var tableNote = table.note ? " Note: '".concat(table.note, "'\n") : '';
|
|
215
223
|
var tableStr = "Table ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\"").concat(tableSettingStr, " {\n").concat(tableContent.fieldContents.map(function (line) {
|
|
216
224
|
return " ".concat(line);
|
|
217
|
-
}).join('\n'), "\n").concat(indexStr ? "".concat(indexStr, "\n") : '', "}\n");
|
|
225
|
+
}).join('\n'), "\n").concat(indexStr ? "".concat(indexStr, "\n") : '').concat(tableNote, "}\n");
|
|
218
226
|
return tableStr;
|
|
219
227
|
});
|
|
220
228
|
return tableStrs.length ? tableStrs.join('\n') : '';
|
|
@@ -11,9 +11,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
11
11
|
|
|
12
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
13
13
|
|
|
14
|
-
var JsonExporter =
|
|
15
|
-
/*#__PURE__*/
|
|
16
|
-
function () {
|
|
14
|
+
var JsonExporter = /*#__PURE__*/function () {
|
|
17
15
|
function JsonExporter() {
|
|
18
16
|
_classCallCheck(this, JsonExporter);
|
|
19
17
|
}
|
|
@@ -23,9 +23,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
23
23
|
|
|
24
24
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
25
25
|
|
|
26
|
-
var ModelExporter =
|
|
27
|
-
/*#__PURE__*/
|
|
28
|
-
function () {
|
|
26
|
+
var ModelExporter = /*#__PURE__*/function () {
|
|
29
27
|
function ModelExporter() {
|
|
30
28
|
_classCallCheck(this, ModelExporter);
|
|
31
29
|
}
|
|
@@ -11,13 +11,17 @@ var _utils = require("./utils");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
14
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
15
15
|
|
|
16
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
16
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
21
|
+
|
|
22
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
23
|
+
|
|
24
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
25
|
|
|
22
26
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
27
|
|
|
@@ -25,9 +29,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
25
29
|
|
|
26
30
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
27
31
|
|
|
28
|
-
var MySQLExporter =
|
|
29
|
-
/*#__PURE__*/
|
|
30
|
-
function () {
|
|
32
|
+
var MySQLExporter = /*#__PURE__*/function () {
|
|
31
33
|
function MySQLExporter() {
|
|
32
34
|
_classCallCheck(this, MySQLExporter);
|
|
33
35
|
}
|
|
@@ -142,7 +144,7 @@ function () {
|
|
|
142
144
|
}).join(',\n'), "\n);\n");
|
|
143
145
|
return tableStr;
|
|
144
146
|
});
|
|
145
|
-
return tableStrs
|
|
147
|
+
return tableStrs;
|
|
146
148
|
}
|
|
147
149
|
}, {
|
|
148
150
|
key: "buildFieldName",
|
|
@@ -197,7 +199,7 @@ function () {
|
|
|
197
199
|
line += ';\n';
|
|
198
200
|
return line;
|
|
199
201
|
});
|
|
200
|
-
return strArr
|
|
202
|
+
return strArr;
|
|
201
203
|
}
|
|
202
204
|
}, {
|
|
203
205
|
key: "exportIndexes",
|
|
@@ -239,7 +241,7 @@ function () {
|
|
|
239
241
|
line += ';\n';
|
|
240
242
|
return line;
|
|
241
243
|
});
|
|
242
|
-
return indexArr
|
|
244
|
+
return indexArr;
|
|
243
245
|
}
|
|
244
246
|
}, {
|
|
245
247
|
key: "exportComments",
|
|
@@ -255,62 +257,68 @@ function () {
|
|
|
255
257
|
line += ';\n';
|
|
256
258
|
return line;
|
|
257
259
|
});
|
|
258
|
-
return commentArr
|
|
260
|
+
return commentArr;
|
|
259
261
|
}
|
|
260
262
|
}, {
|
|
261
263
|
key: "export",
|
|
262
264
|
value: function _export(model) {
|
|
263
|
-
var res = '';
|
|
264
|
-
var hasBlockAbove = false;
|
|
265
265
|
var database = model.database['1'];
|
|
266
|
-
var
|
|
267
|
-
var comments = [];
|
|
268
|
-
database.schemaIds.forEach(function (schemaId) {
|
|
266
|
+
var statements = database.schemaIds.reduce(function (prevStatements, schemaId) {
|
|
269
267
|
var schema = model.schemas[schemaId];
|
|
270
268
|
var tableIds = schema.tableIds,
|
|
271
269
|
refIds = schema.refIds;
|
|
272
270
|
|
|
273
271
|
if ((0, _utils.shouldPrintSchema)(schema, model)) {
|
|
274
|
-
|
|
275
|
-
res += "CREATE DATABASE `".concat(schema.name, "`;\n");
|
|
276
|
-
hasBlockAbove = true;
|
|
272
|
+
prevStatements.schemas.push("CREATE SCHEMA `".concat(schema.name, "`;\n"));
|
|
277
273
|
}
|
|
278
274
|
|
|
279
275
|
if (!_lodash["default"].isEmpty(tableIds)) {
|
|
280
|
-
|
|
281
|
-
res += MySQLExporter.exportTables(tableIds, model);
|
|
282
|
-
hasBlockAbove = true;
|
|
283
|
-
}
|
|
276
|
+
var _prevStatements$table;
|
|
284
277
|
|
|
285
|
-
|
|
286
|
-
if (hasBlockAbove) res += '\n';
|
|
287
|
-
res += MySQLExporter.exportRefs(refIds, model);
|
|
288
|
-
hasBlockAbove = true;
|
|
278
|
+
(_prevStatements$table = prevStatements.tables).push.apply(_prevStatements$table, _toConsumableArray(MySQLExporter.exportTables(tableIds, model)));
|
|
289
279
|
}
|
|
290
280
|
|
|
291
|
-
indexIds
|
|
281
|
+
var indexIds = _lodash["default"].flatten(tableIds.map(function (tableId) {
|
|
292
282
|
return model.tables[tableId].indexIds;
|
|
293
|
-
}))
|
|
294
|
-
|
|
283
|
+
}));
|
|
284
|
+
|
|
285
|
+
if (!_lodash["default"].isEmpty(indexIds)) {
|
|
286
|
+
var _prevStatements$index;
|
|
287
|
+
|
|
288
|
+
(_prevStatements$index = prevStatements.indexes).push.apply(_prevStatements$index, _toConsumableArray(MySQLExporter.exportIndexes(indexIds, model)));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
var commentNodes = _lodash["default"].flatten(tableIds.map(function (tableId) {
|
|
295
292
|
var note = model.tables[tableId].note;
|
|
296
293
|
return note ? [{
|
|
297
294
|
type: 'table',
|
|
298
295
|
tableId: tableId
|
|
299
296
|
}] : [];
|
|
300
|
-
}))
|
|
297
|
+
}));
|
|
298
|
+
|
|
299
|
+
if (!_lodash["default"].isEmpty(commentNodes)) {
|
|
300
|
+
var _prevStatements$comme;
|
|
301
|
+
|
|
302
|
+
(_prevStatements$comme = prevStatements.comments).push.apply(_prevStatements$comme, _toConsumableArray(MySQLExporter.exportComments(commentNodes, model)));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (!_lodash["default"].isEmpty(refIds)) {
|
|
306
|
+
var _prevStatements$refs;
|
|
307
|
+
|
|
308
|
+
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(MySQLExporter.exportRefs(refIds, model)));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return prevStatements;
|
|
312
|
+
}, {
|
|
313
|
+
schemas: [],
|
|
314
|
+
enums: [],
|
|
315
|
+
tables: [],
|
|
316
|
+
indexes: [],
|
|
317
|
+
comments: [],
|
|
318
|
+
refs: []
|
|
301
319
|
});
|
|
302
320
|
|
|
303
|
-
|
|
304
|
-
if (hasBlockAbove) res += '\n';
|
|
305
|
-
res += MySQLExporter.exportIndexes(indexIds, model);
|
|
306
|
-
hasBlockAbove = true;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (!_lodash["default"].isEmpty(comments)) {
|
|
310
|
-
if (hasBlockAbove) res += '\n';
|
|
311
|
-
res += MySQLExporter.exportComments(comments, model);
|
|
312
|
-
hasBlockAbove = true;
|
|
313
|
-
}
|
|
321
|
+
var res = _lodash["default"].concat(statements.schemas, statements.enums, statements.tables, statements.indexes, statements.comments, statements.refs).join('\n');
|
|
314
322
|
|
|
315
323
|
return res;
|
|
316
324
|
}
|
|
@@ -9,15 +9,21 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
|
|
12
|
+
var _config = require("../model_structure/config");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
15
|
|
|
14
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
17
|
+
|
|
18
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
21
|
|
|
16
|
-
function
|
|
22
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
17
23
|
|
|
18
|
-
function
|
|
24
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
25
|
|
|
20
|
-
function
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
27
|
|
|
22
28
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
29
|
|
|
@@ -25,9 +31,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
25
31
|
|
|
26
32
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
27
33
|
|
|
28
|
-
var PostgresExporter =
|
|
29
|
-
/*#__PURE__*/
|
|
30
|
-
function () {
|
|
34
|
+
var PostgresExporter = /*#__PURE__*/function () {
|
|
31
35
|
function PostgresExporter() {
|
|
32
36
|
_classCallCheck(this, PostgresExporter);
|
|
33
37
|
}
|
|
@@ -48,7 +52,7 @@ function () {
|
|
|
48
52
|
var line = "CREATE TYPE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(_enum.name, "\" AS ENUM (\n").concat(enumValueStr, "\n);\n");
|
|
49
53
|
return line;
|
|
50
54
|
});
|
|
51
|
-
return enumArr
|
|
55
|
+
return enumArr;
|
|
52
56
|
}
|
|
53
57
|
}, {
|
|
54
58
|
key: "getFieldLines",
|
|
@@ -61,10 +65,15 @@ function () {
|
|
|
61
65
|
if (field.increment) {
|
|
62
66
|
var typeSerial = field.type.type_name === 'bigint' ? 'BIGSERIAL' : 'SERIAL';
|
|
63
67
|
line = "\"".concat(field.name, "\" ").concat(typeSerial);
|
|
64
|
-
} else if ((0, _utils.hasWhiteSpace)(field.type.type_name)) {
|
|
65
|
-
line = "\"".concat(field.name, "\" \"").concat(field.type.type_name, "\"");
|
|
66
68
|
} else {
|
|
67
|
-
|
|
69
|
+
var schemaName = '';
|
|
70
|
+
|
|
71
|
+
if (field.type.schemaName && field.type.schemaName !== _config.DEFAULT_SCHEMA_NAME) {
|
|
72
|
+
schemaName = (0, _utils.hasWhiteSpace)(field.type.schemaName) ? "\"".concat(field.type.schemaName, "\".") : "".concat(field.type.schemaName, ".");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
var typeName = (0, _utils.hasWhiteSpace)(field.type.type_name) ? "\"".concat(field.type.type_name, "\"") : field.type.type_name;
|
|
76
|
+
line = "\"".concat(field.name, "\" ").concat(schemaName).concat(typeName);
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
if (field.unique) {
|
|
@@ -148,7 +157,7 @@ function () {
|
|
|
148
157
|
}).join(',\n'), "\n);\n");
|
|
149
158
|
return tableStr;
|
|
150
159
|
});
|
|
151
|
-
return tableStrs
|
|
160
|
+
return tableStrs;
|
|
152
161
|
}
|
|
153
162
|
}, {
|
|
154
163
|
key: "buildFieldName",
|
|
@@ -203,7 +212,7 @@ function () {
|
|
|
203
212
|
line += ';\n';
|
|
204
213
|
return line;
|
|
205
214
|
});
|
|
206
|
-
return strArr
|
|
215
|
+
return strArr;
|
|
207
216
|
}
|
|
208
217
|
}, {
|
|
209
218
|
key: "exportIndexes",
|
|
@@ -251,7 +260,7 @@ function () {
|
|
|
251
260
|
line += ';\n';
|
|
252
261
|
return line;
|
|
253
262
|
});
|
|
254
|
-
return indexArr
|
|
263
|
+
return indexArr;
|
|
255
264
|
}
|
|
256
265
|
}, {
|
|
257
266
|
key: "exportComments",
|
|
@@ -282,50 +291,45 @@ function () {
|
|
|
282
291
|
line += ';\n';
|
|
283
292
|
return line;
|
|
284
293
|
});
|
|
285
|
-
return commentArr
|
|
294
|
+
return commentArr;
|
|
286
295
|
}
|
|
287
296
|
}, {
|
|
288
297
|
key: "export",
|
|
289
298
|
value: function _export(model) {
|
|
290
|
-
var res = '';
|
|
291
|
-
var hasBlockAbove = false;
|
|
292
299
|
var database = model.database['1'];
|
|
293
|
-
var
|
|
294
|
-
var comments = [];
|
|
295
|
-
database.schemaIds.forEach(function (schemaId) {
|
|
300
|
+
var statements = database.schemaIds.reduce(function (prevStatements, schemaId) {
|
|
296
301
|
var schema = model.schemas[schemaId];
|
|
297
302
|
var tableIds = schema.tableIds,
|
|
298
303
|
enumIds = schema.enumIds,
|
|
299
304
|
refIds = schema.refIds;
|
|
300
305
|
|
|
301
306
|
if ((0, _utils.shouldPrintSchema)(schema, model)) {
|
|
302
|
-
|
|
303
|
-
res += "CREATE SCHEMA \"".concat(schema.name, "\";\n");
|
|
304
|
-
hasBlockAbove = true;
|
|
307
|
+
prevStatements.schemas.push("CREATE SCHEMA \"".concat(schema.name, "\";\n"));
|
|
305
308
|
}
|
|
306
309
|
|
|
307
310
|
if (!_lodash["default"].isEmpty(enumIds)) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
+
var _prevStatements$enums;
|
|
312
|
+
|
|
313
|
+
(_prevStatements$enums = prevStatements.enums).push.apply(_prevStatements$enums, _toConsumableArray(PostgresExporter.exportEnums(enumIds, model)));
|
|
311
314
|
}
|
|
312
315
|
|
|
313
316
|
if (!_lodash["default"].isEmpty(tableIds)) {
|
|
314
|
-
|
|
315
|
-
res += PostgresExporter.exportTables(tableIds, model);
|
|
316
|
-
hasBlockAbove = true;
|
|
317
|
-
}
|
|
317
|
+
var _prevStatements$table;
|
|
318
318
|
|
|
319
|
-
|
|
320
|
-
if (hasBlockAbove) res += '\n';
|
|
321
|
-
res += PostgresExporter.exportRefs(refIds, model);
|
|
322
|
-
hasBlockAbove = true;
|
|
319
|
+
(_prevStatements$table = prevStatements.tables).push.apply(_prevStatements$table, _toConsumableArray(PostgresExporter.exportTables(tableIds, model)));
|
|
323
320
|
}
|
|
324
321
|
|
|
325
|
-
indexIds
|
|
322
|
+
var indexIds = _lodash["default"].flatten(tableIds.map(function (tableId) {
|
|
326
323
|
return model.tables[tableId].indexIds;
|
|
327
|
-
}))
|
|
328
|
-
|
|
324
|
+
}));
|
|
325
|
+
|
|
326
|
+
if (!_lodash["default"].isEmpty(indexIds)) {
|
|
327
|
+
var _prevStatements$index;
|
|
328
|
+
|
|
329
|
+
(_prevStatements$index = prevStatements.indexes).push.apply(_prevStatements$index, _toConsumableArray(PostgresExporter.exportIndexes(indexIds, model)));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
var commentNodes = _lodash["default"].flatten(tableIds.map(function (tableId) {
|
|
329
333
|
var _model$tables$tableId = model.tables[tableId],
|
|
330
334
|
fieldIds = _model$tables$tableId.fieldIds,
|
|
331
335
|
note = _model$tables$tableId.note;
|
|
@@ -342,20 +346,31 @@ function () {
|
|
|
342
346
|
type: 'table',
|
|
343
347
|
tableId: tableId
|
|
344
348
|
}].concat(fieldObjects) : fieldObjects;
|
|
345
|
-
}))
|
|
349
|
+
}));
|
|
350
|
+
|
|
351
|
+
if (!_lodash["default"].isEmpty(commentNodes)) {
|
|
352
|
+
var _prevStatements$comme;
|
|
353
|
+
|
|
354
|
+
(_prevStatements$comme = prevStatements.comments).push.apply(_prevStatements$comme, _toConsumableArray(PostgresExporter.exportComments(commentNodes, model)));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (!_lodash["default"].isEmpty(refIds)) {
|
|
358
|
+
var _prevStatements$refs;
|
|
359
|
+
|
|
360
|
+
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(PostgresExporter.exportRefs(refIds, model)));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return prevStatements;
|
|
364
|
+
}, {
|
|
365
|
+
schemas: [],
|
|
366
|
+
enums: [],
|
|
367
|
+
tables: [],
|
|
368
|
+
indexes: [],
|
|
369
|
+
comments: [],
|
|
370
|
+
refs: []
|
|
346
371
|
});
|
|
347
372
|
|
|
348
|
-
|
|
349
|
-
if (hasBlockAbove) res += '\n';
|
|
350
|
-
res += PostgresExporter.exportIndexes(indexIds, model);
|
|
351
|
-
hasBlockAbove = true;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (!_lodash["default"].isEmpty(comments)) {
|
|
355
|
-
if (hasBlockAbove) res += '\n';
|
|
356
|
-
res += PostgresExporter.exportComments(comments, model);
|
|
357
|
-
hasBlockAbove = true;
|
|
358
|
-
}
|
|
373
|
+
var res = _lodash["default"].concat(statements.schemas, statements.enums, statements.tables, statements.indexes, statements.comments, statements.refs).join('\n');
|
|
359
374
|
|
|
360
375
|
return res;
|
|
361
376
|
}
|
|
@@ -11,13 +11,17 @@ var _utils = require("./utils");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
14
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
15
15
|
|
|
16
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
16
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
21
|
+
|
|
22
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
23
|
+
|
|
24
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
25
|
|
|
22
26
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
27
|
|
|
@@ -25,9 +29,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
25
29
|
|
|
26
30
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
27
31
|
|
|
28
|
-
var SqlServerExporter =
|
|
29
|
-
/*#__PURE__*/
|
|
30
|
-
function () {
|
|
32
|
+
var SqlServerExporter = /*#__PURE__*/function () {
|
|
31
33
|
function SqlServerExporter() {
|
|
32
34
|
_classCallCheck(this, SqlServerExporter);
|
|
33
35
|
}
|
|
@@ -139,7 +141,7 @@ function () {
|
|
|
139
141
|
}).join(',\n'), "\n)\nGO\n");
|
|
140
142
|
return tableStr;
|
|
141
143
|
});
|
|
142
|
-
return tableStrs
|
|
144
|
+
return tableStrs;
|
|
143
145
|
}
|
|
144
146
|
}, {
|
|
145
147
|
key: "buildFieldName",
|
|
@@ -194,7 +196,7 @@ function () {
|
|
|
194
196
|
line += '\nGO\n';
|
|
195
197
|
return line;
|
|
196
198
|
});
|
|
197
|
-
return strArr
|
|
199
|
+
return strArr;
|
|
198
200
|
}
|
|
199
201
|
}, {
|
|
200
202
|
key: "exportIndexes",
|
|
@@ -231,7 +233,7 @@ function () {
|
|
|
231
233
|
line += '\nGO\n';
|
|
232
234
|
return line;
|
|
233
235
|
});
|
|
234
|
-
return indexArr
|
|
236
|
+
return indexArr;
|
|
235
237
|
}
|
|
236
238
|
}, {
|
|
237
239
|
key: "exportComments",
|
|
@@ -270,49 +272,42 @@ function () {
|
|
|
270
272
|
line += 'GO\n';
|
|
271
273
|
return line;
|
|
272
274
|
});
|
|
273
|
-
return commentArr
|
|
275
|
+
return commentArr;
|
|
274
276
|
}
|
|
275
277
|
}, {
|
|
276
278
|
key: "export",
|
|
277
279
|
value: function _export(model) {
|
|
278
|
-
var res = '';
|
|
279
|
-
var hasBlockAbove = false;
|
|
280
280
|
var database = model.database['1'];
|
|
281
|
-
var
|
|
282
|
-
var comments = [];
|
|
283
|
-
database.schemaIds.forEach(function (schemaId) {
|
|
281
|
+
var statements = database.schemaIds.reduce(function (prevStatements, schemaId) {
|
|
284
282
|
var schema = model.schemas[schemaId];
|
|
285
283
|
var tableIds = schema.tableIds,
|
|
286
284
|
refIds = schema.refIds;
|
|
287
285
|
|
|
288
286
|
if ((0, _utils.shouldPrintSchema)(schema, model)) {
|
|
289
|
-
|
|
290
|
-
res += "CREATE SCHEMA [".concat(schema.name, "];\nGO\n");
|
|
291
|
-
hasBlockAbove = true;
|
|
287
|
+
prevStatements.schemas.push("CREATE SCHEMA [".concat(schema.name, "]\nGO\n"));
|
|
292
288
|
}
|
|
293
289
|
|
|
294
290
|
if (!_lodash["default"].isEmpty(tableIds)) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
291
|
+
var _prevStatements$table;
|
|
292
|
+
|
|
293
|
+
(_prevStatements$table = prevStatements.tables).push.apply(_prevStatements$table, _toConsumableArray(SqlServerExporter.exportTables(tableIds, model)));
|
|
298
294
|
}
|
|
299
295
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
hasBlockAbove = true;
|
|
304
|
-
} /////////PUSH COMMENTS OF TABLE & COLUMN/////////
|
|
305
|
-
// console.log(JSON.stringify(tableIds, null, 2));
|
|
296
|
+
var indexIds = _lodash["default"].flatten(tableIds.map(function (tableId) {
|
|
297
|
+
return model.tables[tableId].indexIds;
|
|
298
|
+
}));
|
|
306
299
|
|
|
300
|
+
if (!_lodash["default"].isEmpty(indexIds)) {
|
|
301
|
+
var _prevStatements$index;
|
|
307
302
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
303
|
+
(_prevStatements$index = prevStatements.indexes).push.apply(_prevStatements$index, _toConsumableArray(SqlServerExporter.exportIndexes(indexIds, model)));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
var commentNodes = _lodash["default"].flatten(tableIds.map(function (tableId) {
|
|
312
307
|
var _model$tables$tableId = model.tables[tableId],
|
|
313
308
|
fieldIds = _model$tables$tableId.fieldIds,
|
|
314
309
|
note = _model$tables$tableId.note;
|
|
315
|
-
var
|
|
310
|
+
var fieldObjects = fieldIds.filter(function (fieldId) {
|
|
316
311
|
return model.fields[fieldId].note;
|
|
317
312
|
}).map(function (fieldId) {
|
|
318
313
|
return {
|
|
@@ -324,21 +319,32 @@ function () {
|
|
|
324
319
|
return note ? [{
|
|
325
320
|
type: 'table',
|
|
326
321
|
tableId: tableId
|
|
327
|
-
}].concat(
|
|
328
|
-
}))
|
|
322
|
+
}].concat(fieldObjects) : fieldObjects;
|
|
323
|
+
}));
|
|
324
|
+
|
|
325
|
+
if (!_lodash["default"].isEmpty(commentNodes)) {
|
|
326
|
+
var _prevStatements$comme;
|
|
327
|
+
|
|
328
|
+
(_prevStatements$comme = prevStatements.comments).push.apply(_prevStatements$comme, _toConsumableArray(SqlServerExporter.exportComments(commentNodes, model)));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (!_lodash["default"].isEmpty(refIds)) {
|
|
332
|
+
var _prevStatements$refs;
|
|
333
|
+
|
|
334
|
+
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(SqlServerExporter.exportRefs(refIds, model)));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return prevStatements;
|
|
338
|
+
}, {
|
|
339
|
+
schemas: [],
|
|
340
|
+
enums: [],
|
|
341
|
+
tables: [],
|
|
342
|
+
indexes: [],
|
|
343
|
+
comments: [],
|
|
344
|
+
refs: []
|
|
329
345
|
});
|
|
330
346
|
|
|
331
|
-
|
|
332
|
-
if (hasBlockAbove) res += '\n';
|
|
333
|
-
res += SqlServerExporter.exportIndexes(indexIds, model);
|
|
334
|
-
hasBlockAbove = true;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (!_lodash["default"].isEmpty(comments)) {
|
|
338
|
-
if (hasBlockAbove) res += '\n';
|
|
339
|
-
res += SqlServerExporter.exportComments(comments, model);
|
|
340
|
-
hasBlockAbove = true;
|
|
341
|
-
}
|
|
347
|
+
var res = _lodash["default"].concat(statements.schemas, statements.enums, statements.tables, statements.indexes, statements.comments, statements.refs).join('\n');
|
|
342
348
|
|
|
343
349
|
return res;
|
|
344
350
|
}
|