@dbml/core 2.4.2 → 2.4.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/lib/export/MysqlExporter.js +11 -42
- package/lib/export/PostgresExporter.js +17 -44
- package/lib/export/SqlServerExporter.js +11 -42
- package/lib/model_structure/endpoint.js +38 -2
- package/lib/parse/mssql/fk_definition/actions.js +4 -2
- package/lib/parse/mysql/parser.pegjs +4 -4
- package/lib/parse/mysqlParser.js +89 -18
- package/lib/parse/postgresParser.js +9 -9
- package/lib/parse/postgresql/Base_rules.pegjs +15 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +16 -11
- package/lib/parse/postgresql/parser.pegjs +1 -0
- package/package.json +2 -2
|
@@ -156,18 +156,18 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
156
156
|
}
|
|
157
157
|
}, {
|
|
158
158
|
key: "buildTableManyToMany",
|
|
159
|
-
value: function buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, tableName) {
|
|
160
|
-
var line = "CREATE TABLE `".concat(tableName, "` (\n");
|
|
159
|
+
value: function buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, tableName, refEndpointSchema, model) {
|
|
160
|
+
var line = "CREATE TABLE ".concat((0, _utils.shouldPrintSchema)(refEndpointSchema, model) ? "`".concat(refEndpointSchema.name, "`.") : '', "`").concat(tableName, "` (\n");
|
|
161
161
|
|
|
162
162
|
var key1s = _toConsumableArray(firstTableFieldsMap.keys()).join('`, `');
|
|
163
163
|
|
|
164
164
|
var key2s = _toConsumableArray(secondTableFieldsMap.keys()).join('`, `');
|
|
165
165
|
|
|
166
166
|
firstTableFieldsMap.forEach(function (fieldType, fieldName) {
|
|
167
|
-
line += " `".concat(fieldName, "` ").concat(fieldType, "
|
|
167
|
+
line += " `".concat(fieldName, "` ").concat(fieldType, ",\n");
|
|
168
168
|
});
|
|
169
169
|
secondTableFieldsMap.forEach(function (fieldType, fieldName) {
|
|
170
|
-
line += " `".concat(fieldName, "` ").concat(fieldType, "
|
|
170
|
+
line += " `".concat(fieldName, "` ").concat(fieldType, ",\n");
|
|
171
171
|
});
|
|
172
172
|
line += " PRIMARY KEY (`".concat(key1s, "`, `").concat(key2s, "`)\n");
|
|
173
173
|
line += ');\n\n';
|
|
@@ -175,34 +175,15 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
175
175
|
}
|
|
176
176
|
}, {
|
|
177
177
|
key: "buildForeignKeyManyToMany",
|
|
178
|
-
value: function buildForeignKeyManyToMany(fieldsMap, foreignEndpointFields, refEndpointTableName, foreignEndpointTableName,
|
|
178
|
+
value: function buildForeignKeyManyToMany(fieldsMap, foreignEndpointFields, refEndpointTableName, foreignEndpointTableName, refEndpointSchema, foreignEndpointSchema, model) {
|
|
179
179
|
var refEndpointFields = _toConsumableArray(fieldsMap.keys()).join('`, `');
|
|
180
180
|
|
|
181
|
-
var line = "ALTER TABLE `".concat(refEndpointTableName, "` ADD FOREIGN KEY (`").concat(refEndpointFields, "`) REFERENCES ").concat((0, _utils.shouldPrintSchema)(
|
|
182
|
-
return line;
|
|
183
|
-
}
|
|
184
|
-
}, {
|
|
185
|
-
key: "buildIndexManytoMany",
|
|
186
|
-
value: function buildIndexManytoMany(fieldsMap, newTableName, tableRefName, usedIndexNames) {
|
|
187
|
-
var newIndexName = "".concat(newTableName, "_").concat(tableRefName);
|
|
188
|
-
var count = 1;
|
|
189
|
-
|
|
190
|
-
while (usedIndexNames.has(newIndexName)) {
|
|
191
|
-
newIndexName = "".concat(newTableName, "_").concat(tableRefName, "(").concat(count, ")");
|
|
192
|
-
count += 1;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
usedIndexNames.add(newIndexName);
|
|
196
|
-
|
|
197
|
-
var indexFields = _toConsumableArray(fieldsMap.keys()).join('`, `');
|
|
198
|
-
|
|
199
|
-
var line = "CREATE INDEX `idx_".concat(newIndexName, "` ON `").concat(newTableName, "` (");
|
|
200
|
-
line += "`".concat(indexFields, "`);\n\n");
|
|
181
|
+
var line = "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(refEndpointSchema, model) ? "`".concat(refEndpointSchema.name, "`.") : '', "`").concat(refEndpointTableName, "` ADD FOREIGN KEY (`").concat(refEndpointFields, "`) REFERENCES ").concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "`".concat(foreignEndpointSchema.name, "`.") : '', "`").concat(foreignEndpointTableName, "` ").concat(foreignEndpointFields, ";\n\n");
|
|
201
182
|
return line;
|
|
202
183
|
}
|
|
203
184
|
}, {
|
|
204
185
|
key: "exportRefs",
|
|
205
|
-
value: function exportRefs(refIds, model, usedTableNames
|
|
186
|
+
value: function exportRefs(refIds, model, usedTableNames) {
|
|
206
187
|
var _this = this;
|
|
207
188
|
|
|
208
189
|
var strArr = refIds.map(function (refId) {
|
|
@@ -232,18 +213,9 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
232
213
|
var firstTableFieldsMap = (0, _utils.buildJunctionFields1)(refEndpoint.fieldIds, model);
|
|
233
214
|
var secondTableFieldsMap = (0, _utils.buildJunctionFields2)(foreignEndpoint.fieldIds, model, firstTableFieldsMap);
|
|
234
215
|
var newTableName = (0, _utils.buildNewTableName)(refEndpointTable.name, foreignEndpointTable.name, usedTableNames);
|
|
235
|
-
line += _this.buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, newTableName);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
line += _this.buildIndexManytoMany(firstTableFieldsMap, newTableName, refEndpointTable.name, usedIndexNames);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (secondTableFieldsMap.size > 1) {
|
|
242
|
-
line += _this.buildIndexManytoMany(secondTableFieldsMap, newTableName, foreignEndpointTable.name, usedIndexNames);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
line += _this.buildForeignKeyManyToMany(firstTableFieldsMap, refEndpointFieldName, newTableName, refEndpointTable.name, refEndpointSchema, model);
|
|
246
|
-
line += _this.buildForeignKeyManyToMany(secondTableFieldsMap, foreignEndpointFieldName, newTableName, foreignEndpointTable.name, foreignEndpointSchema, model);
|
|
216
|
+
line += _this.buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, newTableName, refEndpointSchema, model);
|
|
217
|
+
line += _this.buildForeignKeyManyToMany(firstTableFieldsMap, refEndpointFieldName, newTableName, refEndpointTable.name, refEndpointSchema, refEndpointSchema, model);
|
|
218
|
+
line += _this.buildForeignKeyManyToMany(secondTableFieldsMap, foreignEndpointFieldName, newTableName, foreignEndpointTable.name, refEndpointSchema, foreignEndpointSchema, model);
|
|
247
219
|
} else {
|
|
248
220
|
line = "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "`".concat(foreignEndpointSchema.name, "`.") : '', "`").concat(foreignEndpointTable.name, "` ADD ");
|
|
249
221
|
|
|
@@ -333,9 +305,6 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
333
305
|
var usedTableNames = new Set(Object.values(model.tables).map(function (table) {
|
|
334
306
|
return table.name;
|
|
335
307
|
}));
|
|
336
|
-
var usedIndexNames = new Set(Object.values(model.indexes).map(function (index) {
|
|
337
|
-
return index.name;
|
|
338
|
-
}));
|
|
339
308
|
var statements = database.schemaIds.reduce(function (prevStatements, schemaId) {
|
|
340
309
|
var schema = model.schemas[schemaId];
|
|
341
310
|
var tableIds = schema.tableIds,
|
|
@@ -378,7 +347,7 @@ var MySQLExporter = /*#__PURE__*/function () {
|
|
|
378
347
|
if (!_lodash["default"].isEmpty(refIds)) {
|
|
379
348
|
var _prevStatements$refs;
|
|
380
349
|
|
|
381
|
-
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(MySQLExporter.exportRefs(refIds, model, usedTableNames
|
|
350
|
+
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(MySQLExporter.exportRefs(refIds, model, usedTableNames)));
|
|
382
351
|
}
|
|
383
352
|
|
|
384
353
|
return prevStatements;
|
|
@@ -63,8 +63,12 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
63
63
|
var line = '';
|
|
64
64
|
|
|
65
65
|
if (field.increment) {
|
|
66
|
-
var
|
|
67
|
-
|
|
66
|
+
var typicalIntergers = new Set(['BIGINT', 'INT', 'INTEGER', 'SMALLINT']);
|
|
67
|
+
var incrementIntergers = new Set(['SMALLSERIAL', 'SERIAL', 'BIGSERIAL']);
|
|
68
|
+
var typeRaw = field.type.type_name.toUpperCase();
|
|
69
|
+
var type = '';
|
|
70
|
+
if (typicalIntergers.has(typeRaw)) type = "".concat(typeRaw, " GENERATED BY DEFAULT AS IDENTITY");else if (incrementIntergers.has(typeRaw)) type = typeRaw;else type = 'SERIAL';
|
|
71
|
+
line = "\"".concat(field.name, "\" ").concat(type);
|
|
68
72
|
} else {
|
|
69
73
|
var schemaName = '';
|
|
70
74
|
|
|
@@ -169,18 +173,18 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
169
173
|
}
|
|
170
174
|
}, {
|
|
171
175
|
key: "buildTableManyToMany",
|
|
172
|
-
value: function buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, tableName) {
|
|
173
|
-
var line = "CREATE TABLE \"".concat(tableName, "\" (\n");
|
|
176
|
+
value: function buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, tableName, refEndpointSchema, model) {
|
|
177
|
+
var line = "CREATE TABLE ".concat((0, _utils.shouldPrintSchema)(refEndpointSchema, model) ? "\"".concat(refEndpointSchema.name, "\".") : '', "\"").concat(tableName, "\" (\n");
|
|
174
178
|
|
|
175
179
|
var key1s = _toConsumableArray(firstTableFieldsMap.keys()).join('", "');
|
|
176
180
|
|
|
177
181
|
var key2s = _toConsumableArray(secondTableFieldsMap.keys()).join('", "');
|
|
178
182
|
|
|
179
183
|
firstTableFieldsMap.forEach(function (fieldType, fieldName) {
|
|
180
|
-
line += " \"".concat(fieldName, "\" ").concat(fieldType, "
|
|
184
|
+
line += " \"".concat(fieldName, "\" ").concat(fieldType, ",\n");
|
|
181
185
|
});
|
|
182
186
|
secondTableFieldsMap.forEach(function (fieldType, fieldName) {
|
|
183
|
-
line += " \"".concat(fieldName, "\" ").concat(fieldType, "
|
|
187
|
+
line += " \"".concat(fieldName, "\" ").concat(fieldType, ",\n");
|
|
184
188
|
});
|
|
185
189
|
line += " PRIMARY KEY (\"".concat(key1s, "\", \"").concat(key2s, "\")\n");
|
|
186
190
|
line += ');\n\n';
|
|
@@ -188,34 +192,15 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
188
192
|
}
|
|
189
193
|
}, {
|
|
190
194
|
key: "buildForeignKeyManyToMany",
|
|
191
|
-
value: function buildForeignKeyManyToMany(fieldsMap, foreignEndpointFields, refEndpointTableName, foreignEndpointTableName,
|
|
195
|
+
value: function buildForeignKeyManyToMany(fieldsMap, foreignEndpointFields, refEndpointTableName, foreignEndpointTableName, refEndpointSchema, foreignEndpointSchema, model) {
|
|
192
196
|
var refEndpointFields = _toConsumableArray(fieldsMap.keys()).join('", "');
|
|
193
197
|
|
|
194
|
-
var line = "ALTER TABLE \"".concat(refEndpointTableName, "\" ADD FOREIGN KEY (\"").concat(refEndpointFields, "\") REFERENCES ").concat((0, _utils.shouldPrintSchema)(
|
|
195
|
-
return line;
|
|
196
|
-
}
|
|
197
|
-
}, {
|
|
198
|
-
key: "buildIndexManytoMany",
|
|
199
|
-
value: function buildIndexManytoMany(fieldsMap, newTableName, tableRefName, usedIndexNames) {
|
|
200
|
-
var newIndexName = "".concat(newTableName, "_").concat(tableRefName);
|
|
201
|
-
var count = 1;
|
|
202
|
-
|
|
203
|
-
while (usedIndexNames.has(newIndexName)) {
|
|
204
|
-
newIndexName = "".concat(newTableName, "_").concat(tableRefName, "(").concat(count, ")");
|
|
205
|
-
count += 1;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
usedIndexNames.add(newIndexName);
|
|
209
|
-
|
|
210
|
-
var indexFields = _toConsumableArray(fieldsMap.keys()).join('", "');
|
|
211
|
-
|
|
212
|
-
var line = "CREATE INDEX \"idx_".concat(newIndexName, "\" ON \"").concat(newTableName, "\" (");
|
|
213
|
-
line += "\"".concat(indexFields, "\");\n\n");
|
|
198
|
+
var line = "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(refEndpointSchema, model) ? "\"".concat(refEndpointSchema.name, "\".") : '', "\"").concat(refEndpointTableName, "\" ADD FOREIGN KEY (\"").concat(refEndpointFields, "\") REFERENCES ").concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "\"".concat(foreignEndpointSchema.name, "\".") : '', "\"").concat(foreignEndpointTableName, "\" ").concat(foreignEndpointFields, ";\n\n");
|
|
214
199
|
return line;
|
|
215
200
|
}
|
|
216
201
|
}, {
|
|
217
202
|
key: "exportRefs",
|
|
218
|
-
value: function exportRefs(refIds, model, usedTableNames
|
|
203
|
+
value: function exportRefs(refIds, model, usedTableNames) {
|
|
219
204
|
var _this = this;
|
|
220
205
|
|
|
221
206
|
var strArr = refIds.map(function (refId) {
|
|
@@ -246,18 +231,9 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
246
231
|
var firstTableFieldsMap = (0, _utils.buildJunctionFields1)(refEndpoint.fieldIds, model);
|
|
247
232
|
var secondTableFieldsMap = (0, _utils.buildJunctionFields2)(foreignEndpoint.fieldIds, model, firstTableFieldsMap);
|
|
248
233
|
var newTableName = (0, _utils.buildNewTableName)(refEndpointTable.name, foreignEndpointTable.name, usedTableNames);
|
|
249
|
-
line += _this.buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, newTableName);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
line += _this.buildIndexManytoMany(firstTableFieldsMap, newTableName, refEndpointTable.name, usedIndexNames);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (secondTableFieldsMap.size > 1) {
|
|
256
|
-
line += _this.buildIndexManytoMany(secondTableFieldsMap, newTableName, foreignEndpointTable.name, usedIndexNames);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
line += _this.buildForeignKeyManyToMany(firstTableFieldsMap, refEndpointFieldName, newTableName, refEndpointTable.name, refEndpointSchema, model);
|
|
260
|
-
line += _this.buildForeignKeyManyToMany(secondTableFieldsMap, foreignEndpointFieldName, newTableName, foreignEndpointTable.name, foreignEndpointSchema, model);
|
|
234
|
+
line += _this.buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, newTableName, refEndpointSchema, model);
|
|
235
|
+
line += _this.buildForeignKeyManyToMany(firstTableFieldsMap, refEndpointFieldName, newTableName, refEndpointTable.name, refEndpointSchema, refEndpointSchema, model);
|
|
236
|
+
line += _this.buildForeignKeyManyToMany(secondTableFieldsMap, foreignEndpointFieldName, newTableName, foreignEndpointTable.name, refEndpointSchema, foreignEndpointSchema, model);
|
|
261
237
|
} else {
|
|
262
238
|
line = "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "\"".concat(foreignEndpointSchema.name, "\".") : '', "\"").concat(foreignEndpointTable.name, "\" ADD ");
|
|
263
239
|
|
|
@@ -368,9 +344,6 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
368
344
|
var usedTableNames = new Set(Object.values(model.tables).map(function (table) {
|
|
369
345
|
return table.name;
|
|
370
346
|
}));
|
|
371
|
-
var usedIndexNames = new Set(Object.values(model.indexes).map(function (index) {
|
|
372
|
-
return index.name;
|
|
373
|
-
}));
|
|
374
347
|
var statements = database.schemaIds.reduce(function (prevStatements, schemaId) {
|
|
375
348
|
var schema = model.schemas[schemaId];
|
|
376
349
|
var tableIds = schema.tableIds,
|
|
@@ -431,7 +404,7 @@ var PostgresExporter = /*#__PURE__*/function () {
|
|
|
431
404
|
if (!_lodash["default"].isEmpty(refIds)) {
|
|
432
405
|
var _prevStatements$refs;
|
|
433
406
|
|
|
434
|
-
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(PostgresExporter.exportRefs(refIds, model, usedTableNames
|
|
407
|
+
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(PostgresExporter.exportRefs(refIds, model, usedTableNames)));
|
|
435
408
|
}
|
|
436
409
|
|
|
437
410
|
return prevStatements;
|
|
@@ -145,18 +145,18 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
145
145
|
}
|
|
146
146
|
}, {
|
|
147
147
|
key: "buildTableManyToMany",
|
|
148
|
-
value: function buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, tableName) {
|
|
149
|
-
var line = "CREATE TABLE [".concat(tableName, "] (\n");
|
|
148
|
+
value: function buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, tableName, refEndpointSchema, model) {
|
|
149
|
+
var line = "CREATE TABLE ".concat((0, _utils.shouldPrintSchema)(refEndpointSchema, model) ? "[".concat(refEndpointSchema.name, "].") : '', "[").concat(tableName, "] (\n");
|
|
150
150
|
|
|
151
151
|
var key1s = _toConsumableArray(firstTableFieldsMap.keys()).join('], [');
|
|
152
152
|
|
|
153
153
|
var key2s = _toConsumableArray(secondTableFieldsMap.keys()).join('], [');
|
|
154
154
|
|
|
155
155
|
firstTableFieldsMap.forEach(function (fieldType, fieldName) {
|
|
156
|
-
line += " [".concat(fieldName, "] ").concat(fieldType, "
|
|
156
|
+
line += " [".concat(fieldName, "] ").concat(fieldType, ",\n");
|
|
157
157
|
});
|
|
158
158
|
secondTableFieldsMap.forEach(function (fieldType, fieldName) {
|
|
159
|
-
line += " [".concat(fieldName, "] ").concat(fieldType, "
|
|
159
|
+
line += " [".concat(fieldName, "] ").concat(fieldType, ",\n");
|
|
160
160
|
});
|
|
161
161
|
line += " PRIMARY KEY ([".concat(key1s, "], [").concat(key2s, "])\n");
|
|
162
162
|
line += ');\nGO\n\n';
|
|
@@ -164,29 +164,10 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
164
164
|
}
|
|
165
165
|
}, {
|
|
166
166
|
key: "buildForeignKeyManyToMany",
|
|
167
|
-
value: function buildForeignKeyManyToMany(fieldsMap, foreignEndpointFields, refEndpointTableName, foreignEndpointTableName,
|
|
167
|
+
value: function buildForeignKeyManyToMany(fieldsMap, foreignEndpointFields, refEndpointTableName, foreignEndpointTableName, refEndpointSchema, foreignEndpointSchema, model) {
|
|
168
168
|
var refEndpointFields = _toConsumableArray(fieldsMap.keys()).join('], [');
|
|
169
169
|
|
|
170
|
-
var line = "ALTER TABLE [".concat(refEndpointTableName, "] ADD FOREIGN KEY ([").concat(refEndpointFields, "]) REFERENCES ").concat((0, _utils.shouldPrintSchema)(
|
|
171
|
-
return line;
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "buildIndexManytoMany",
|
|
175
|
-
value: function buildIndexManytoMany(fieldsMap, newTableName, tableRefName, usedIndexNames) {
|
|
176
|
-
var newIndexName = "".concat(newTableName, "_").concat(tableRefName);
|
|
177
|
-
var count = 1;
|
|
178
|
-
|
|
179
|
-
while (usedIndexNames.has(newIndexName)) {
|
|
180
|
-
newIndexName = "".concat(newTableName, "_").concat(tableRefName, "(").concat(count, ")");
|
|
181
|
-
count += 1;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
usedIndexNames.add(newIndexName);
|
|
185
|
-
|
|
186
|
-
var indexFields = _toConsumableArray(fieldsMap.keys()).join('", "');
|
|
187
|
-
|
|
188
|
-
var line = "CREATE INDEX [idx_".concat(newIndexName, "] ON [").concat(newTableName, "] (");
|
|
189
|
-
line += "\"".concat(indexFields, "\");\nGO\n\n");
|
|
170
|
+
var line = "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(refEndpointSchema, model) ? "[".concat(refEndpointSchema.name, "].") : '', "[").concat(refEndpointTableName, "] ADD FOREIGN KEY ([").concat(refEndpointFields, "]) REFERENCES ").concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "[".concat(foreignEndpointSchema.name, "].") : '', "[").concat(foreignEndpointTableName, "] ").concat(foreignEndpointFields, ";\nGO\n\n");
|
|
190
171
|
return line;
|
|
191
172
|
}
|
|
192
173
|
}, {
|
|
@@ -199,7 +180,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
199
180
|
}
|
|
200
181
|
}, {
|
|
201
182
|
key: "exportRefs",
|
|
202
|
-
value: function exportRefs(refIds, model, usedTableNames
|
|
183
|
+
value: function exportRefs(refIds, model, usedTableNames) {
|
|
203
184
|
var _this = this;
|
|
204
185
|
|
|
205
186
|
var strArr = refIds.map(function (refId) {
|
|
@@ -230,18 +211,9 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
230
211
|
var firstTableFieldsMap = (0, _utils.buildJunctionFields1)(refEndpoint.fieldIds, model);
|
|
231
212
|
var secondTableFieldsMap = (0, _utils.buildJunctionFields2)(foreignEndpoint.fieldIds, model, firstTableFieldsMap);
|
|
232
213
|
var newTableName = (0, _utils.buildNewTableName)(refEndpointTable.name, foreignEndpointTable.name, usedTableNames);
|
|
233
|
-
line += _this.buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, newTableName);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
line += _this.buildIndexManytoMany(firstTableFieldsMap, newTableName, refEndpointTable.name, usedIndexNames);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (secondTableFieldsMap.size > 1) {
|
|
240
|
-
line += _this.buildIndexManytoMany(secondTableFieldsMap, newTableName, foreignEndpointTable.name, usedIndexNames);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
line += _this.buildForeignKeyManyToMany(firstTableFieldsMap, refEndpointFieldName, newTableName, refEndpointTable.name, refEndpointSchema, model);
|
|
244
|
-
line += _this.buildForeignKeyManyToMany(secondTableFieldsMap, foreignEndpointFieldName, newTableName, foreignEndpointTable.name, foreignEndpointSchema, model);
|
|
214
|
+
line += _this.buildTableManyToMany(firstTableFieldsMap, secondTableFieldsMap, newTableName, refEndpointSchema, model);
|
|
215
|
+
line += _this.buildForeignKeyManyToMany(firstTableFieldsMap, refEndpointFieldName, newTableName, refEndpointTable.name, refEndpointSchema, refEndpointSchema, model);
|
|
216
|
+
line += _this.buildForeignKeyManyToMany(secondTableFieldsMap, foreignEndpointFieldName, newTableName, foreignEndpointTable.name, refEndpointSchema, foreignEndpointSchema, model);
|
|
245
217
|
} else {
|
|
246
218
|
line = "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "[".concat(foreignEndpointSchema.name, "].") : '', "[").concat(foreignEndpointTable.name, "] ADD ");
|
|
247
219
|
|
|
@@ -349,9 +321,6 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
349
321
|
var usedTableNames = new Set(Object.values(model.tables).map(function (table) {
|
|
350
322
|
return table.name;
|
|
351
323
|
}));
|
|
352
|
-
var usedIndexNames = new Set(Object.values(model.indexes).map(function (index) {
|
|
353
|
-
return index.name;
|
|
354
|
-
}));
|
|
355
324
|
var statements = database.schemaIds.reduce(function (prevStatements, schemaId) {
|
|
356
325
|
var schema = model.schemas[schemaId];
|
|
357
326
|
var tableIds = schema.tableIds,
|
|
@@ -405,7 +374,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
|
|
|
405
374
|
if (!_lodash["default"].isEmpty(refIds)) {
|
|
406
375
|
var _prevStatements$refs;
|
|
407
376
|
|
|
408
|
-
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(SqlServerExporter.exportRefs(refIds, model, usedTableNames
|
|
377
|
+
(_prevStatements$refs = prevStatements.refs).push.apply(_prevStatements$refs, _toConsumableArray(SqlServerExporter.exportRefs(refIds, model, usedTableNames)));
|
|
409
378
|
}
|
|
410
379
|
|
|
411
380
|
return prevStatements;
|
|
@@ -15,6 +15,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
15
15
|
|
|
16
16
|
function _typeof(obj) { "@babel/helpers - typeof"; 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); }
|
|
17
17
|
|
|
18
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
19
|
+
|
|
20
|
+
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."); }
|
|
21
|
+
|
|
22
|
+
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); }
|
|
23
|
+
|
|
24
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
25
|
+
|
|
26
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
18
30
|
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; }
|
|
19
31
|
|
|
20
32
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -140,11 +152,35 @@ var Endpoint = /*#__PURE__*/function (_Element) {
|
|
|
140
152
|
value: function setFields(fieldNames, table) {
|
|
141
153
|
var _this2 = this;
|
|
142
154
|
|
|
143
|
-
fieldNames.
|
|
155
|
+
var newFieldNames = fieldNames && fieldNames.length ? _toConsumableArray(fieldNames) : [];
|
|
156
|
+
|
|
157
|
+
if (!newFieldNames.length) {
|
|
158
|
+
var fieldHasPK = table.fields.find(function (field) {
|
|
159
|
+
return field.pk;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (fieldHasPK) {
|
|
163
|
+
newFieldNames.push(fieldHasPK.name);
|
|
164
|
+
} else {
|
|
165
|
+
var indexHasPK = table.indexes.find(function (index) {
|
|
166
|
+
return index.pk;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (indexHasPK) {
|
|
170
|
+
newFieldNames = indexHasPK.columns.map(function (column) {
|
|
171
|
+
return column.value;
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
this.error("Can't find primary or composite key in table ".concat((0, _utils.shouldPrintSchema)(table.schema) ? "\"".concat(table.schema.name, "\".") : '', "\"").concat(table.name, "\""));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
newFieldNames.forEach(function (fieldName) {
|
|
144
180
|
var field = table.findField(fieldName);
|
|
145
181
|
|
|
146
182
|
if (!field) {
|
|
147
|
-
_this2.error("Can't find field ".concat((0, _utils.shouldPrintSchema)(table.schema) ? "\"".concat(table.schema.name, "\".") : '', "\"").concat(fieldName, "\" in table \"").concat(
|
|
183
|
+
_this2.error("Can't find field ".concat((0, _utils.shouldPrintSchema)(table.schema) ? "\"".concat(table.schema.name, "\".") : '', "\"").concat(fieldName, "\" in table \"").concat(table.name, "\""));
|
|
148
184
|
}
|
|
149
185
|
|
|
150
186
|
_this2.fields.push(field);
|
|
@@ -51,12 +51,14 @@ function makeTableConstraintFK(_keyword1, endpoint1, _keyword2, tableName, endpo
|
|
|
51
51
|
var fullTableName = getFullTableName(tableName);
|
|
52
52
|
|
|
53
53
|
if (!endpoint2) {
|
|
54
|
+
// 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
|
|
54
55
|
// eslint-disable-next-line no-param-reassign
|
|
55
56
|
endpoint2 = {
|
|
56
57
|
type: 'endpoint',
|
|
57
|
-
value: {
|
|
58
|
+
value: {
|
|
59
|
+
fieldNames: null
|
|
60
|
+
}
|
|
58
61
|
};
|
|
59
|
-
endpoint2.value.fieldNames = endpoint1.value.fieldNames;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
endpoint1.value.relation = '*';
|
|
@@ -190,7 +190,7 @@ UniqueSyntax
|
|
|
190
190
|
// "KEY is normally a synonym for INDEX".
|
|
191
191
|
IndexInLineSyntax = _ unique:index_in_line
|
|
192
192
|
_ name:name? _ type1:index_type? _
|
|
193
|
-
"(" _ columns:IndexColumnValues _")"
|
|
193
|
+
"(" _ columns:IndexColumnValues _")" type2:(_ IndexOption)?
|
|
194
194
|
{
|
|
195
195
|
const index = { columns };
|
|
196
196
|
if(name) {
|
|
@@ -199,9 +199,8 @@ IndexInLineSyntax = _ unique:index_in_line
|
|
|
199
199
|
if(unique) {
|
|
200
200
|
index.unique = true;
|
|
201
201
|
}
|
|
202
|
-
|
|
203
|
-
if(type
|
|
204
|
-
index.type = type;
|
|
202
|
+
if(type2 && type2[1] && type2[1].type === 'index_type' && type2[1].value ) index.type = type2[1].value;
|
|
203
|
+
else if(type1) index.type = type1;
|
|
205
204
|
return index;
|
|
206
205
|
}
|
|
207
206
|
index_in_line // keyword
|
|
@@ -257,6 +256,7 @@ FieldSetting "field setting"
|
|
|
257
256
|
) { return "not_supported" }
|
|
258
257
|
/ _ v:Default {return {type: "default", value: v} }
|
|
259
258
|
/ _ v:Comment { return {type: "comment", value: v }}
|
|
259
|
+
/ _ "ON"i _ "UPDATE"i _ type { return "not_supported" }
|
|
260
260
|
|
|
261
261
|
// Default: Support "DEFAULT (value|expr)" syntax
|
|
262
262
|
Default
|
package/lib/parse/mysqlParser.js
CHANGED
|
@@ -357,8 +357,7 @@ function peg$parse(input, options) {
|
|
|
357
357
|
index.unique = true;
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
-
|
|
361
|
-
if (type) index.type = type;
|
|
360
|
+
if (type2 && type2[1] && type2[1].type === 'index_type' && type2[1].value) index.type = type2[1].value;else if (type1) index.type = type1;
|
|
362
361
|
return index;
|
|
363
362
|
},
|
|
364
363
|
peg$c30 = "index",
|
|
@@ -2428,7 +2427,7 @@ function peg$parse(input, options) {
|
|
|
2428
2427
|
}
|
|
2429
2428
|
|
|
2430
2429
|
function peg$parseIndexInLineSyntax() {
|
|
2431
|
-
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
|
|
2430
|
+
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15;
|
|
2432
2431
|
s0 = peg$currPos;
|
|
2433
2432
|
s1 = peg$parse_();
|
|
2434
2433
|
|
|
@@ -2492,27 +2491,32 @@ function peg$parse(input, options) {
|
|
|
2492
2491
|
}
|
|
2493
2492
|
|
|
2494
2493
|
if (s12 !== peg$FAILED) {
|
|
2495
|
-
s13 = peg$
|
|
2494
|
+
s13 = peg$currPos;
|
|
2495
|
+
s14 = peg$parse_();
|
|
2496
|
+
|
|
2497
|
+
if (s14 !== peg$FAILED) {
|
|
2498
|
+
s15 = peg$parseIndexOption();
|
|
2499
|
+
|
|
2500
|
+
if (s15 !== peg$FAILED) {
|
|
2501
|
+
s14 = [s14, s15];
|
|
2502
|
+
s13 = s14;
|
|
2503
|
+
} else {
|
|
2504
|
+
peg$currPos = s13;
|
|
2505
|
+
s13 = peg$FAILED;
|
|
2506
|
+
}
|
|
2507
|
+
} else {
|
|
2508
|
+
peg$currPos = s13;
|
|
2509
|
+
s13 = peg$FAILED;
|
|
2510
|
+
}
|
|
2496
2511
|
|
|
2497
2512
|
if (s13 === peg$FAILED) {
|
|
2498
2513
|
s13 = null;
|
|
2499
2514
|
}
|
|
2500
2515
|
|
|
2501
2516
|
if (s13 !== peg$FAILED) {
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
s14 = null;
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
if (s14 !== peg$FAILED) {
|
|
2509
|
-
peg$savedPos = s0;
|
|
2510
|
-
s1 = peg$c29(s2, s4, s6, s10, s14);
|
|
2511
|
-
s0 = s1;
|
|
2512
|
-
} else {
|
|
2513
|
-
peg$currPos = s0;
|
|
2514
|
-
s0 = peg$FAILED;
|
|
2515
|
-
}
|
|
2517
|
+
peg$savedPos = s0;
|
|
2518
|
+
s1 = peg$c29(s2, s4, s6, s10, s13);
|
|
2519
|
+
s0 = s1;
|
|
2516
2520
|
} else {
|
|
2517
2521
|
peg$currPos = s0;
|
|
2518
2522
|
s0 = peg$FAILED;
|
|
@@ -3689,6 +3693,73 @@ function peg$parse(input, options) {
|
|
|
3689
3693
|
peg$currPos = s0;
|
|
3690
3694
|
s0 = peg$FAILED;
|
|
3691
3695
|
}
|
|
3696
|
+
|
|
3697
|
+
if (s0 === peg$FAILED) {
|
|
3698
|
+
s0 = peg$currPos;
|
|
3699
|
+
s1 = peg$parse_();
|
|
3700
|
+
|
|
3701
|
+
if (s1 !== peg$FAILED) {
|
|
3702
|
+
if (input.substr(peg$currPos, 2).toLowerCase() === peg$c17) {
|
|
3703
|
+
s2 = input.substr(peg$currPos, 2);
|
|
3704
|
+
peg$currPos += 2;
|
|
3705
|
+
} else {
|
|
3706
|
+
s2 = peg$FAILED;
|
|
3707
|
+
|
|
3708
|
+
if (peg$silentFails === 0) {
|
|
3709
|
+
peg$fail(peg$c18);
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
|
|
3713
|
+
if (s2 !== peg$FAILED) {
|
|
3714
|
+
s3 = peg$parse_();
|
|
3715
|
+
|
|
3716
|
+
if (s3 !== peg$FAILED) {
|
|
3717
|
+
if (input.substr(peg$currPos, 6).toLowerCase() === peg$c19) {
|
|
3718
|
+
s4 = input.substr(peg$currPos, 6);
|
|
3719
|
+
peg$currPos += 6;
|
|
3720
|
+
} else {
|
|
3721
|
+
s4 = peg$FAILED;
|
|
3722
|
+
|
|
3723
|
+
if (peg$silentFails === 0) {
|
|
3724
|
+
peg$fail(peg$c20);
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
|
|
3728
|
+
if (s4 !== peg$FAILED) {
|
|
3729
|
+
s5 = peg$parse_();
|
|
3730
|
+
|
|
3731
|
+
if (s5 !== peg$FAILED) {
|
|
3732
|
+
s6 = peg$parsetype();
|
|
3733
|
+
|
|
3734
|
+
if (s6 !== peg$FAILED) {
|
|
3735
|
+
peg$savedPos = s0;
|
|
3736
|
+
s1 = peg$c79();
|
|
3737
|
+
s0 = s1;
|
|
3738
|
+
} else {
|
|
3739
|
+
peg$currPos = s0;
|
|
3740
|
+
s0 = peg$FAILED;
|
|
3741
|
+
}
|
|
3742
|
+
} else {
|
|
3743
|
+
peg$currPos = s0;
|
|
3744
|
+
s0 = peg$FAILED;
|
|
3745
|
+
}
|
|
3746
|
+
} else {
|
|
3747
|
+
peg$currPos = s0;
|
|
3748
|
+
s0 = peg$FAILED;
|
|
3749
|
+
}
|
|
3750
|
+
} else {
|
|
3751
|
+
peg$currPos = s0;
|
|
3752
|
+
s0 = peg$FAILED;
|
|
3753
|
+
}
|
|
3754
|
+
} else {
|
|
3755
|
+
peg$currPos = s0;
|
|
3756
|
+
s0 = peg$FAILED;
|
|
3757
|
+
}
|
|
3758
|
+
} else {
|
|
3759
|
+
peg$currPos = s0;
|
|
3760
|
+
s0 = peg$FAILED;
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3692
3763
|
}
|
|
3693
3764
|
}
|
|
3694
3765
|
}
|