@dbml/core 5.1.0 → 5.3.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.
Files changed (53) hide show
  1. package/lib/export/DbmlExporter.js +3 -2
  2. package/lib/export/MysqlExporter.js +2 -2
  3. package/lib/export/OracleExporter.js +2 -2
  4. package/lib/export/PostgresExporter.js +2 -2
  5. package/lib/export/SqlServerExporter.js +2 -2
  6. package/lib/model_structure/element.js +1 -3
  7. package/lib/parse/ANTLR/ASTGeneration/AST.js +0 -2
  8. package/lib/parse/ANTLR/ASTGeneration/constants.js +1 -0
  9. package/lib/parse/ANTLR/ASTGeneration/index.js +16 -3
  10. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +1 -1
  11. package/lib/parse/ANTLR/ASTGeneration/mssql/README.md +157 -0
  12. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +1 -1
  13. package/lib/parse/ANTLR/ASTGeneration/mysql/README.md +157 -0
  14. package/lib/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.js +1161 -0
  15. package/lib/parse/ANTLR/ASTGeneration/oraclesql/README.md +157 -0
  16. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +2 -3
  17. package/lib/parse/ANTLR/ASTGeneration/postgres/README.md +157 -0
  18. package/lib/parse/ANTLR/ASTGeneration/snowflake/README.md +157 -0
  19. package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +1 -1
  20. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +60 -2
  21. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +25 -4
  22. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +1235 -1171
  23. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +2306 -2300
  24. package/lib/parse/ANTLR/parsers/mysql/MySqlLexerBase.js +52 -0
  25. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +6 -4
  26. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +15 -3
  27. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +2 -2
  28. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +2306 -2300
  29. package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +1 -1
  30. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.g4 +2623 -0
  31. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.interp +7475 -0
  32. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.js +3 -0
  33. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.tokens +4934 -0
  34. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexerBase.js +35 -0
  35. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.g4 +9988 -0
  36. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.interp +6174 -0
  37. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.js +3 -0
  38. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.tokens +4934 -0
  39. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserBase.js +64 -0
  40. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserVisitor.js +8466 -0
  41. package/lib/parse/Parser.js +8 -0
  42. package/lib/parse/buildParser.js +1 -1
  43. package/lib/parse/databaseGenerator.js +2 -2
  44. package/lib/parse/error.js +0 -1
  45. package/lib/parse/mssql/fk_definition/actions.js +1 -1
  46. package/lib/parse/mssql/index.js +0 -1
  47. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -1
  48. package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -2
  49. package/lib/parse/mssql/statements/statement_types/comments/index.js +2 -2
  50. package/lib/parse/mssql/utils.js +0 -1
  51. package/package.json +16 -5
  52. package/types/import/index.d.ts +1 -1
  53. package/types/parse/Parser.d.ts +3 -1
@@ -49,7 +49,7 @@ var DbmlExporter = /*#__PURE__*/function () {
49
49
  // Only safe chars, no simple quotes nor CR/LF
50
50
  return "'".concat(newStr, "'");
51
51
  }
52
- newStr = newStr.replaceAll("'", "\\'");
52
+ newStr = newStr.replaceAll('\'', '\\\'');
53
53
  newStr = newStr.replaceAll('\r\n', '\n'); // turn all CRLF to LF
54
54
  return "'''".concat(newStr, "'''");
55
55
  }
@@ -103,7 +103,7 @@ var DbmlExporter = /*#__PURE__*/function () {
103
103
  break;
104
104
  case 'string':
105
105
  {
106
- var quote = field.dbdefault.value.includes('\n') ? "'''" : "'";
106
+ var quote = field.dbdefault.value.includes('\n') ? '\'\'\'' : '\'';
107
107
  value += "".concat(quote).concat(field.dbdefault.value).concat(quote);
108
108
  break;
109
109
  }
@@ -111,6 +111,7 @@ var DbmlExporter = /*#__PURE__*/function () {
111
111
  value += "`".concat(field.dbdefault.value, "`");
112
112
  break;
113
113
  default:
114
+ value += "`".concat(field.dbdefault.value, "`");
114
115
  break;
115
116
  }
116
117
  constraints.push(value);
@@ -77,7 +77,7 @@ var MySQLExporter = /*#__PURE__*/function () {
77
77
  }
78
78
  }
79
79
  if (field.note) {
80
- line += " COMMENT '".concat(field.note.replace(/'/g, "''"), "'");
80
+ line += " COMMENT '".concat(field.note.replace(/'/g, '\'\''), "'");
81
81
  }
82
82
  return line;
83
83
  });
@@ -281,7 +281,7 @@ var MySQLExporter = /*#__PURE__*/function () {
281
281
  if (comment.type === 'table') {
282
282
  var table = model.tables[comment.tableId];
283
283
  var schema = model.schemas[table.schemaId];
284
- line += "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "`".concat(schema.name, "`.") : '', "`").concat(table.name, "` COMMENT = '").concat(table.note.replace(/'/g, "''"), "'");
284
+ line += "ALTER TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "`".concat(schema.name, "`.") : '', "`").concat(table.name, "` COMMENT = '").concat(table.note.replace(/'/g, '\'\''), "'");
285
285
  }
286
286
  line += ';\n';
287
287
  return line;
@@ -401,13 +401,13 @@ var OracleExporter = /*#__PURE__*/function () {
401
401
  switch (comment.type) {
402
402
  case 'table':
403
403
  {
404
- line += " TABLE ".concat(tableName, " IS '").concat(table.note.replace(/'/g, "''"), "'");
404
+ line += " TABLE ".concat(tableName, " IS '").concat(table.note.replace(/'/g, '\'\''), "'");
405
405
  break;
406
406
  }
407
407
  case 'column':
408
408
  {
409
409
  var field = model.fields[comment.fieldId];
410
- line += " COLUMN ".concat(tableName, ".").concat((0, _utils.escapeObjectName)(field.name, 'oracle'), " IS '").concat(field.note.replace(/'/g, "''"), "'");
410
+ line += " COLUMN ".concat(tableName, ".").concat((0, _utils.escapeObjectName)(field.name, 'oracle'), " IS '").concat(field.note.replace(/'/g, '\'\''), "'");
411
411
  break;
412
412
  }
413
413
  default:
@@ -355,13 +355,13 @@ var PostgresExporter = /*#__PURE__*/function () {
355
355
  switch (comment.type) {
356
356
  case 'table':
357
357
  {
358
- line += " TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\" IS '").concat(table.note.replace(/'/g, "''"), "'");
358
+ line += " TABLE ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\" IS '").concat(table.note.replace(/'/g, '\'\''), "'");
359
359
  break;
360
360
  }
361
361
  case 'column':
362
362
  {
363
363
  var field = model.fields[comment.fieldId];
364
- line += " COLUMN ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\".\"").concat(field.name, "\" IS '").concat(field.note.replace(/'/g, "''"), "'");
364
+ line += " COLUMN ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\".\"").concat(field.name, "\" IS '").concat(field.note.replace(/'/g, '\'\''), "'");
365
365
  break;
366
366
  }
367
367
  default:
@@ -281,7 +281,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
281
281
  case 'table':
282
282
  {
283
283
  line += '@name = N\'Table_Description\',\n';
284
- line += "@value = '".concat(table.note.replace(/'/g, "''"), "',\n");
284
+ line += "@value = '".concat(table.note.replace(/'/g, '\'\''), "',\n");
285
285
  line += "@level0type = N'Schema', @level0name = '".concat((0, _utils.shouldPrintSchema)(schema, model) ? "".concat(schema.name) : 'dbo', "',\n");
286
286
  line += "@level1type = N'Table', @level1name = '".concat(table.name, "';\n");
287
287
  break;
@@ -290,7 +290,7 @@ var SqlServerExporter = /*#__PURE__*/function () {
290
290
  {
291
291
  var field = model.fields[comment.fieldId];
292
292
  line += '@name = N\'Column_Description\',\n';
293
- line += "@value = '".concat(field.note.replace(/'/g, "''"), "',\n");
293
+ line += "@value = '".concat(field.note.replace(/'/g, '\'\''), "',\n");
294
294
  line += "@level0type = N'Schema', @level0name = '".concat((0, _utils.shouldPrintSchema)(schema, model) ? "".concat(schema.name) : 'dbo', "',\n");
295
295
  line += "@level1type = N'Table', @level1name = '".concat(table.name, "',\n");
296
296
  line += "@level2type = N'Column', @level2name = '".concat(field.name, "';\n");
@@ -20,7 +20,6 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
20
20
  function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
21
21
  function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
22
22
  function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
23
- /* eslint-disable */
24
23
  var ElementError = /*#__PURE__*/function (_Error) {
25
24
  function ElementError(message) {
26
25
  var _this;
@@ -56,5 +55,4 @@ var Element = /*#__PURE__*/function () {
56
55
  }
57
56
  }]);
58
57
  }();
59
- var _default = exports["default"] = Element;
60
- /* eslint-enable */
58
+ var _default = exports["default"] = Element;
@@ -10,8 +10,6 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
10
10
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- /* eslint-disable camelcase */
14
- /* eslint-disable max-classes-per-file */
15
13
  var Index = exports.Index = /*#__PURE__*/function () {
16
14
  /**
17
15
  * @param {{
@@ -15,6 +15,7 @@ var TABLE_CONSTRAINT_KIND = exports.TABLE_CONSTRAINT_KIND = {
15
15
  };
16
16
  var COLUMN_CONSTRAINT_KIND = exports.COLUMN_CONSTRAINT_KIND = {
17
17
  NOT_NULL: 'not_null',
18
+ NULLABLE: 'nullable',
18
19
  UNIQUE: 'unique',
19
20
  PK: 'pk',
20
21
  DEFAULT: 'dbdefault',
@@ -18,10 +18,10 @@ var _ParserErrorListener = _interopRequireDefault(require("./ParserErrorListener
18
18
  var _TSqlLexer = _interopRequireDefault(require("../parsers/mssql/TSqlLexer"));
19
19
  var _TSqlParser = _interopRequireDefault(require("../parsers/mssql/TSqlParser"));
20
20
  var _MssqlASTGen = _interopRequireDefault(require("./mssql/MssqlASTGen"));
21
+ var _OracleSqlLexer = _interopRequireDefault(require("../parsers/oraclesql/OracleSqlLexer"));
22
+ var _OracleSqlParser = _interopRequireDefault(require("../parsers/oraclesql/OracleSqlParser"));
23
+ var _OracleSQLASTGen = _interopRequireDefault(require("./oraclesql/OracleSQLASTGen"));
21
24
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
22
- /* eslint-disable import/no-named-as-default-member */
23
- /* eslint-disable import/no-named-as-default */
24
-
25
25
  function parse(input, format) {
26
26
  var chars = new _antlr["default"].InputStream(input);
27
27
  var database = null;
@@ -79,6 +79,19 @@ function parse(input, format) {
79
79
  if (errorListener.errors.length) throw errorListener.errors;
80
80
  break;
81
81
  }
82
+ case 'oracle':
83
+ {
84
+ var _lexer4 = new _OracleSqlLexer["default"](chars);
85
+ var _tokens4 = new _antlr["default"].CommonTokenStream(_lexer4);
86
+ var _parser4 = new _OracleSqlParser["default"](_tokens4);
87
+ _parser4.buildParseTrees = true;
88
+ _parser4.removeErrorListeners();
89
+ _parser4.addErrorListener(errorListener);
90
+ var _parseTree4 = _parser4.sql_script();
91
+ database = _parseTree4.accept(new _OracleSQLASTGen["default"]());
92
+ if (errorListener.errors.length) throw errorListener.errors;
93
+ break;
94
+ }
82
95
  default:
83
96
  throw new Error("Format not supported: ".concat(format));
84
97
  }
@@ -35,7 +35,7 @@ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructur
35
35
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
36
36
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
37
37
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
38
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /* eslint-disable class-methods-use-this */
38
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
39
39
  var ADD_DESCRIPTION_FUNCTION_NAME = 'sp_addextendedproperty';
40
40
  var getSchemaAndTableName = function getSchemaAndTableName(names) {
41
41
  var tableName = (0, _lodash.last)(names);
@@ -0,0 +1,157 @@
1
+ # MSSQL model structure generator
2
+
3
+ This folder houses the implementation of the MSSQL model structure generator based on the ANTLR4 parser.
4
+
5
+ This file documents the current features and bugs of this model structure generator.
6
+
7
+ In the below table, the following notation is used:
8
+ - ✅: Supported.
9
+ - 🤷🏼‍♂️: Invalid SQL in MSSQL.
10
+ - ❓: Valid SQL in MSSQL, the generator can still generate output but it ignores this syntax.
11
+ - ❌: Valid SQL in MSSQL, but the generator fails to generate any output.
12
+
13
+ | SQL syntax | MSSQL |
14
+ |-------------------------------|---------------|
15
+ | 1. INSERT statement | |
16
+ | 1.a. Basic INSERT ... VALUES | ✅ |
17
+ | 1.b. INSERT ... SELECT | ❌ |
18
+ | 1.c. Multi-row INSERT | ✅ |
19
+ | 1.d. Common table expression (WITH clause) | ❌ |
20
+ | 1.e. Target table alias | 🤷🏼‍♂️ |
21
+ | 1.f. INSERT … OUTPUT | ❓ (ignore the OUTPUT clause) |
22
+ | 1.g. INSERT ... ON CONFLICT (UPSERT)/INSERT ... ON DUPLICATE KEY/INSERT … IGNORE | 🤷🏼‍♂️ |
23
+ | 1.h. INSERT OVERWRITE | 🤷🏼‍♂️ |
24
+ | 1.i. Multi-table INSERT | ❌ |
25
+ | 1.j. Conditional multi-table INSERT (WHEN/FIRST/ALL) | ❌ |
26
+ | 6. CREATE TABLE | |
27
+ | 6.a. Basic syntax | ✅ |
28
+ | 6.a.i. Enumerated data type | 🤷🏼‍♂️ |
29
+ | 6.a.ii. Data type of the form name(...) | ✅ |
30
+ | 6.a.iii. Data type of the form name\[...\] | 🤷🏼‍♂️ |
31
+ | 6.b. PRIMARY KEY | |
32
+ | 6.b.i. Inline PRIMARY KEY | ✅ |
33
+ | 6.b.ii. Out-of-line PRIMARY KEY | ✅ |
34
+ | 6.b.iii. Composite PRIMARY KEY | ✅ |
35
+ | 6.b.iv. Named PRIMARY KEY | ✅ |
36
+ | 6.b.v. Other options (deferrable, etc.) | ❓ (ignore the options) |
37
+ | 6.c. FOREIGN KEY | |
38
+ | 6.c.i. Inline FOREIGN KEY | ❌ (bug) |
39
+ | 6.c.ii. Out-of-line FOREIGN KEY | ❌ (bug) |
40
+ | 6.c.iii. Composite FOREIGN KEY | ❌ (bug) |
41
+ | 6.c.iv. Named FOREIGN KEY | ❌ (bug) |
42
+ | 6.c.v. ON UPDATE | ❌ (bug) |
43
+ | 6.c.vi. ON DELETE | ❌ (bug) |
44
+ | 6.c.vii. Other options (deferrable, etc.) | ❌ (bug) |
45
+ | 6.d. UNIQUE | |
46
+ | 6.d.i. Inline UNIQUE | ✅ |
47
+ | 6.d.ii. Out-of-line UNIQUE | ✅ |
48
+ | 6.d.iii. Composite UNIQUE | ✅ |
49
+ | 6.d.iv. Named UNIQUE | ❓ (ignore the name) |
50
+ | 6.d.v. Other options (deferrable, etc) | ❓ (ignore the option) |
51
+ | 6.d.vi. NULLS NOT DISTINCT | 🤷🏼‍♂️ |
52
+ | 6.d.vii. UNIQUE KEY/UNIQUE INDEX | 🤷🏼‍♂️ |
53
+ | 6.e. CHECK | |
54
+ | 6.e.i. Inline CHECK | ❌ (parse fail) |
55
+ | 6.e.ii. Out-of-line CHECK | ❌ (parse fail) |
56
+ | 6.e.iii. Named CHECK | ❌ (parse fail) |
57
+ | 6.e.iv. Other options (enforcement control, etc.) | ❌ (parse fail) |
58
+ | 6.f. DEFAULT values | |
59
+ | 6.f.i. Inline DEFAULT | ✅ |
60
+ | 6.f.ii. Out-of-line DEFAULT | ❌ (Totally ignore) |
61
+ | 6.f.iii. Functional DEFAULT | ✅ |
62
+ | 6.f.iv. Named DEFAULT | ❓ (ignore the name) |
63
+ | 6.g. NULL | ✅ |
64
+ | 6.h. NOT NULL | |
65
+ | 6.h.i. Inline NOT NULL | ✅ |
66
+ | 6.h.ii. Out-of-line NOT NULL | 🤷🏼‍♂️ |
67
+ | 6.h.iii. Named NOT NULL | 🤷🏼‍♂️ |
68
+ | 6.h.iv. Other options (deferrable, etc.) | ❓ (Ignore) |
69
+ | 6.i. Indexes | |
70
+ | 6.i.i. Inline indexes | 🤷🏼‍♂️ (except for UNIQUE/PRIMARY KEY) |
71
+ | 6.i.ii. Out-of-line indexes | 🤷🏼‍♂️ (except for UNIQUE/PRIMARY KEY) |
72
+ | 6.i.iii. Named indexes | 🤷🏼‍♂️ |
73
+ | 6.i.iv. Multi-column indexes | 🤷🏼‍♂️ |
74
+ | 6.i.v. CLUSTERED/NONCLUSTERED | ❓ (ignore) |
75
+ | 6.i.vi. FULLTEXT | 🤷🏼‍♂️ |
76
+ | 6.i.vii. SPATIAL | 🤷🏼‍♂️ |
77
+ | 6.i.viii. Other options | 🤷🏼‍♂️ |
78
+ | 6.i.ix. USING HASH/BTREE | 🤷🏼‍♂️ |
79
+ | 6.j. Auto-increment | |
80
+ | 6.j.i. AUTO_INCREMENT | 🤷🏼‍♂️ |
81
+ | 6.j.ii. SERIAL/BIG SERIAL | 🤷🏼‍♂️ |
82
+ | 6.j.iii. IDENTITY | ✅ |
83
+ | 6.j.iv. Increment range | ✅ |
84
+ | 6.j.v. GENERATED ... AS IDENTITY | ❌ (parse fail) |
85
+ | 6.k. Computed column | ❓ |
86
+ | 6.l. TEMPORARY tables | ✅ (indication of temporary table via # prefix) |
87
+ | 6.m. CREATE TABLE AS SELECT (CTAS) | ❌ |
88
+ | 6.n. Comments | |
89
+ | 6.n.i. Table comments | 🤷🏼‍♂️ |
90
+ | 6.n.ii. Column comments | 🤷🏼‍♂️ |
91
+ | 6.o. Other options (inheritance, UNLOGGED, partition, collate, etc.) | ❓ |
92
+ | 7. ALTER TABLE | |
93
+ | 7.a. ADD COLUMN | |
94
+ | 7.a.i. Type | ❌ |
95
+ | 7.a.ii. DEFAULT | ❌ |
96
+ | 7.a.iii. NOT NULL | ❌ |
97
+ | 7.a.iv. NULL | ❌ |
98
+ | 7.a.v. CHECK | ❌ |
99
+ | 7.a.vi. UNIQUE | ❌ |
100
+ | 7.a.vii. FOREIGN KEY | ❌ (parse fail) |
101
+ | 7.a.viii. PRIMARY KEY | ❌ |
102
+ | 7.a.ix. AUTOINCREMENT/SERIAL/BIGSERIAL/IDENTITY/GENERATED AS IDENTITY | ❌ |
103
+ | 7.a.x. Computed column | ❌ |
104
+ | 7.b. DROP COLUMN | ❌ |
105
+ | 7.c. ALTER COLUMN / MODIFY COLUMN | |
106
+ | 7.c.i. COMMENT | 🤷🏼‍♂️ |
107
+ | 7.c.ii. Others | ❌ |
108
+ | 7.d. RENAME COLUMN | ❌ |
109
+ | 7.e. ADD CONSTRAINT | |
110
+ | 7.e.i. DEFAULT | ✅ (ignore name) |
111
+ | 7.e.ii. NOT NULL | ❌ |
112
+ | 7.e.iii. NULL | ❌ |
113
+ | 7.e.iv. named CHECK | ✅ |
114
+ | 7.e.v. unnamed CHECK | ✅ |
115
+ | 7.e.vi. named UNIQUE | ✅ |
116
+ | 7.e.vii. unnamed UNIQUE | ✅ |
117
+ | 7.e.viii. named PRIMARY KEY | ✅ |
118
+ | 7.e.ix. unnamed PRIMARY KEY | ✅ |
119
+ | 7.e.x. named FOREIGN KEY | ✅ |
120
+ | 7.e.xi. unnamed FOREIGN KEY | ✅ |
121
+ | 7.g. DROP CONSTRAINT | ❌ |
122
+ | 7.h. ALTER CONSTRAINT | ❌ |
123
+ | 7.i. RENAME TABLE | ❌ |
124
+ | 7.j. SET SCHEMA | ❌ |
125
+ | 7.k. ALTER INDEX | ❌ |
126
+ | 7.l. DROP INDEX | ❌ |
127
+ | 7.m. SET COMMENT/COMMENT = | 🤷🏼‍♂️ |
128
+ | 7.n. ADD INDEX | ❌ |
129
+ | 8. DROP TABLE | |
130
+ | 8.a. Basic syntax | ❌ |
131
+ | 9. CREATE INDEX | |
132
+ | 9.a. Basic syntax | ✅ |
133
+ | 9.b. Composite index | ✅ |
134
+ | 9.c. Named index | ✅ |
135
+ | 9.d. UNIQUE index | ✅ |
136
+ | 9.e. Partial/Filtered index | ❓ (ignore) |
137
+ | 9.f. BTREE/HASH/GIST/BRIN/… index | ❌ (parse fail) |
138
+ | 9.g. INCLUDE columns | ❓ (ignore) |
139
+ | 9.h. CLUSTERED/NONCLUSTERED | ❓ (ignore) |
140
+ | 9.i. Functional index | 🤷🏼‍♂️ (However, the MSSQL exporter is currently exporting this syntax) |
141
+ | 9.j. FULLTEXT/SPATIAL index | ❌ (parse fail) |
142
+ | 9.k. COLLATE | 🤷🏼‍♂️ |
143
+ | 9.l. COMMENT | 🤷🏼‍♂️ |
144
+ | 9.m. NULLS LAST/FIRST | 🤷🏼‍♂️ |
145
+ | 9.n. ASC/DESC | ❓ (ignore) |
146
+ | 10. DROP INDEX | |
147
+ | 10.a. Basic syntax | ❌ |
148
+ | 11. ALTER INDEX | |
149
+ | 11.a. RENAME | ❌ |
150
+ | 11.b. ALTER COLUMN | ❌ |
151
+ | 12. CREATE VIEW | |
152
+ | 12.a. Basic syntax | ❌ |
153
+ | 13. Comment | |
154
+ | 13.a. Table comments | ✅ (but unreliable) |
155
+ | 13.b. Column comments | ✅ (but unreliable) |
156
+ | 13.c. COMMENT … IS NULL | ✅ (but unreliable) |
157
+ | 13.d. Index comments | ❌ |
@@ -35,7 +35,7 @@ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError(
35
35
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
36
36
  function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
37
37
  function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
38
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } /* eslint-disable class-methods-use-this */
38
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
39
39
  var TABLE_OPTIONS_KIND = {
40
40
  NOTE: 'note'
41
41
  };
@@ -0,0 +1,157 @@
1
+ # MySQL model structure generator
2
+
3
+ This folder houses the implementation of the MySQL model structure generator based on the ANTLR4 parser.
4
+
5
+ This file documents the current features and bugs of this model structure generator.
6
+
7
+ In the below table, the following notation is used:
8
+ - ✅: Supported.
9
+ - 🤷🏼‍♂️: Invalid SQL in MySQL.
10
+ - ❓: Valid SQL in MySQL, the generator can still generate output but it ignores this syntax.
11
+ - ❌: Valid SQL in MySQL, but the generator fails to generate any output.
12
+
13
+ | SQL syntax | MySQL |
14
+ |-------------------------------|---------------|
15
+ | 1. INSERT statement | |
16
+ | 1.a. Basic INSERT ... VALUES | ✅ |
17
+ | 1.b. INSERT ... SELECT | ❌ |
18
+ | 1.c. Multi-row INSERT | ✅ |
19
+ | 1.d. Common table expression (WITH clause) | ❌ |
20
+ | 1.e. Target table alias | 🤷🏼‍♂️ |
21
+ | 1.f. INSERT ... RETURNING/INSERT … OUTPUT | 🤷🏼‍♂️ |
22
+ | 1.g. INSERT ... ON CONFLICT (UPSERT)/INSERT ... ON DUPLICATE KEY/INSERT … IGNORE | ❓ (ignore the ON DUPLICATE KEY and IGNORE clauses) |
23
+ | 1.h. INSERT OVERWRITE | 🤷🏼‍♂️ |
24
+ | 1.i. Multi-table INSERT | ❌ |
25
+ | 1.j. Conditional multi-table INSERT (WHEN/FIRST/ALL) | ❌ |
26
+ | 6. CREATE TABLE | |
27
+ | 6.a. Basic syntax | ✅ |
28
+ | 6.a.i. Enumerated data type | 🤷🏼‍♂️ |
29
+ | 6.a.ii. Data type of the form name(...) | ✅ |
30
+ | 6.a.iii. Data type of the form name\[...\] | 🤷🏼‍♂️ |
31
+ | 6.b. PRIMARY KEY | |
32
+ | 6.b.i. Inline PRIMARY KEY | ✅ |
33
+ | 6.b.ii. Out-of-line PRIMARY KEY | ✅ |
34
+ | 6.b.iii. Composite PRIMARY KEY | ✅ |
35
+ | 6.b.iv. Named PRIMARY KEY | ✅ |
36
+ | 6.b.v. Other options (deferrable, etc.) | ❓ (ignore the options) |
37
+ | 6.c. FOREIGN KEY | |
38
+ | 6.c.i. Inline FOREIGN KEY | ✅ |
39
+ | 6.c.ii. Out-of-line FOREIGN KEY | ✅ |
40
+ | 6.c.iii. Composite FOREIGN KEY | ✅ |
41
+ | 6.c.iv. Named FOREIGN KEY | ✅ |
42
+ | 6.c.v. ON UPDATE | ✅ |
43
+ | 6.c.vi. ON DELETE | ✅ |
44
+ | 6.c.vii. Other options (deferrable, etc.) | ❓ (ignore the options) |
45
+ | 6.d. UNIQUE | |
46
+ | 6.d.i. Inline UNIQUE | ✅ |
47
+ | 6.d.ii. Out-of-line UNIQUE | ✅ |
48
+ | 6.d.iii. Composite UNIQUE | ✅ |
49
+ | 6.d.iv. Named UNIQUE | ✅ |
50
+ | 6.d.v. Other options (deferrable, etc) | ❓ (ignore the option) |
51
+ | 6.d.vi. NULLS NOT DISTINCT | ❌ (parse fail) |
52
+ | 6.d.vii. UNIQUE KEY/UNIQUE INDEX | ✅ |
53
+ | 6.e. CHECK | |
54
+ | 6.e.i. Inline CHECK | ✅ |
55
+ | 6.e.ii. Out-of-line CHECK | ✅ |
56
+ | 6.e.iii. Named CHECK | ✅ (ignored for inline checks) |
57
+ | 6.e.iv. Other options (enforcement control, etc.) | ❓ (ignore the options) |
58
+ | 6.f. DEFAULT values | |
59
+ | 6.f.i. Inline DEFAULT | ✅ |
60
+ | 6.f.ii. Out-of-line DEFAULT | 🤷🏼‍♂️ |
61
+ | 6.f.iii. Functional DEFAULT | ✅ |
62
+ | 6.f.iv. Named DEFAULT | 🤷🏼‍♂️ |
63
+ | 6.g. NULL | ✅ |
64
+ | 6.h. NOT NULL | |
65
+ | 6.h.i. Inline NOT NULL | ✅ |
66
+ | 6.h.ii. Out-of-line NOT NULL | 🤷🏼‍♂️ |
67
+ | 6.h.iii. Named NOT NULL | 🤷🏼‍♂️ |
68
+ | 6.h.iv. Other options (deferrable, etc.) | ❓ (ignore) |
69
+ | 6.i. Indexes | |
70
+ | 6.i.i. Inline indexes | ❌ (parse fail) |
71
+ | 6.i.ii. Out-of-line indexes | ✅ |
72
+ | 6.i.iii. Named indexes | ✅ |
73
+ | 6.i.iv. Multi-column indexes | ✅ |
74
+ | 6.i.v. CLUSTERED/NONCLUSTERED | 🤷🏼‍♂️ |
75
+ | 6.i.vi. FULLTEXT | ❓ (ignore) |
76
+ | 6.i.vii. SPATIAL | ❓ (ignore) |
77
+ | 6.i.viii. Other options | ❓ (ignore) |
78
+ | 6.i.ix. USING HASH/BTREE | ✅ |
79
+ | 6.j. Auto-increment | |
80
+ | 6.j.i. AUTO_INCREMENT | ✅ |
81
+ | 6.j.ii. SERIAL/BIG SERIAL | 🤷🏼‍♂️ |
82
+ | 6.j.iii. IDENTITY | 🤷🏼‍♂️ |
83
+ | 6.j.iv. Increment range | ❓ (ignore) |
84
+ | 6.j.v. GENERATED ... AS IDENTITY | 🤷🏼‍♂️ |
85
+ | 6.k. Computed column | ❓ |
86
+ | 6.l. TEMPORARY tables | ❌ (Totally ignored) |
87
+ | 6.m. CREATE TABLE AS SELECT (CTAS) | ❌ |
88
+ | 6.n. Comments | |
89
+ | 6.n.i. Table comments | ✅ |
90
+ | 6.n.ii. Column comments | ✅ |
91
+ | 6.o. Other options (inheritance, UNLOGGED, partition, collate, etc.) | ❓ |
92
+ | 7. ALTER TABLE | |
93
+ | 7.a. ADD COLUMN | |
94
+ | 7.a.i. Type | ❌ |
95
+ | 7.a.ii. DEFAULT | ❌ |
96
+ | 7.a.iii. NOT NULL | ❌ |
97
+ | 7.a.iv. NULL | ❌ |
98
+ | 7.a.v. CHECK | ❌ |
99
+ | 7.a.vi. UNIQUE | ❌ (parse fail when giving a name) |
100
+ | 7.a.vii. FOREIGN KEY | ❌ (parse fail for FOREIGN KEY name REFERENCES ...) |
101
+ | 7.a.viii. PRIMARY KEY | ❌ |
102
+ | 7.a.ix. AUTOINCREMENT/SERIAL/BIGSERIAL/IDENTITY/GENERATED AS IDENTITY | ❌ |
103
+ | 7.a.x. Computed column | ❌ |
104
+ | 7.b. DROP COLUMN | ❌ |
105
+ | 7.c. ALTER COLUMN / MODIFY COLUMN | |
106
+ | 7.c.i. COMMENT | ❌ |
107
+ | 7.c.ii. Others | ❌ |
108
+ | 7.d. RENAME COLUMN | ❌ |
109
+ | 7.e. ADD CONSTRAINT | |
110
+ | 7.e.i. DEFAULT | ❌ (parse fail) |
111
+ | 7.e.ii. NOT NULL | ❌ |
112
+ | 7.e.iii. NULL | ❌ |
113
+ | 7.e.iv. named CHECK | ✅ |
114
+ | 7.e.v. unnamed CHECK | ✅ |
115
+ | 7.e.vi. named UNIQUE | ❌ |
116
+ | 7.e.vii. unnamed UNIQUE | ❌ |
117
+ | 7.e.viii. named PRIMARY KEY | ❓ (ignore name) |
118
+ | 7.e.ix. unnamed PRIMARY KEY | ✅ |
119
+ | 7.e.x. named FOREIGN KEY | ✅ |
120
+ | 7.e.xi. unnamed FOREIGN KEY | ✅ |
121
+ | 7.g. DROP CONSTRAINT | ❌ |
122
+ | 7.h. ALTER CONSTRAINT | ❌ |
123
+ | 7.i. RENAME TABLE | ❌ |
124
+ | 7.j. SET SCHEMA | ❌ |
125
+ | 7.k. ALTER INDEX | ❌ |
126
+ | 7.l. DROP INDEX | ❌ |
127
+ | 7.m. SET COMMENT/COMMENT = | ❌ |
128
+ | 7.n. ADD INDEX | ❌ |
129
+ | 8. DROP TABLE | |
130
+ | 8.a. Basic syntax | ❌ |
131
+ | 9. CREATE INDEX | |
132
+ | 9.a. Basic syntax | ✅ |
133
+ | 9.b. Composite index | ✅ |
134
+ | 9.c. Named index | ✅ |
135
+ | 9.d. UNIQUE index | ✅ |
136
+ | 9.e. Partial/Filtered index | ❌ (parse fail) |
137
+ | 9.f. BTREE/HASH/GIST/BRIN/… index | ✅ |
138
+ | 9.g. INCLUDE columns | 🤷🏼‍♂️ |
139
+ | 9.h. CLUSTERED/NONCLUSTERED | ❓ (ignore) |
140
+ | 9.i. Functional index | ✅ |
141
+ | 9.j. FULLTEXT/SPATIAL index | ❓ (ignore) |
142
+ | 9.k. COLLATE | ❌ (parse fail) |
143
+ | 9.l. COMMENT | ❓ (ignore) |
144
+ | 9.m. NULLS LAST/FIRST | 🤷🏼‍♂️ |
145
+ | 9.n. ASC/DESC | ❓ (ignore) |
146
+ | 10. DROP INDEX | |
147
+ | 10.a. Basic syntax | ❌ |
148
+ | 11. ALTER INDEX | 🤷🏼‍♂️ |
149
+ | 11.a. RENAME | 🤷🏼‍♂️ |
150
+ | 11.b. ALTER COLUMN | 🤷🏼‍♂️ |
151
+ | 12. CREATE VIEW | |
152
+ | 12.a. Basic syntax | ❌ |
153
+ | 13. Comment | |
154
+ | 13.a. Table comments | 🤷🏼‍♂️ |
155
+ | 13.b. Column comments | 🤷🏼‍♂️ |
156
+ | 13.c. COMMENT … IS NULL | 🤷🏼‍♂️ |
157
+ | 13.d. Index comments | ❌ (parse fail) |