@dbml/core 5.1.0 → 5.2.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 +1154 -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
@@ -0,0 +1,157 @@
1
+ # OracleSQL model structure generator
2
+
3
+ This folder houses the implementation of the OracleSQL 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 OracleSQL.
10
+ - ❓: Valid SQL in OracleSQL, the generator can still generate output but it ignores this syntax.
11
+ - ❌: Valid SQL in OracleSQL, but the generator fails to generate any output.
12
+
13
+ | SQL syntax | OracleSQL |
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 | 🤷🏼‍♂️ |
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 | 🤷🏼‍♂️ (but supported in Oracle 23ai) |
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.) | ❓ |
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) | ❓ |
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 | ✅ |
55
+ | 6.e.ii. Out-of-line CHECK | ✅ |
56
+ | 6.e.iii. Named CHECK | ✅ |
57
+ | 6.e.iv. Other options (enforcement control, etc.) | ❓ |
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.) | ❓ |
69
+ | 6.i. Indexes | |
70
+ | 6.i.i. Inline indexes | 🤷🏼‍♂️ |
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 | 🤷🏼‍♂️ |
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 | ✅ |
85
+ | 6.k. Computed column | ❓ |
86
+ | 6.l. TEMPORARY tables | ❓ (No indication of temporary table) |
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 | ❌ |
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 | ✅ |
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 | 🤷🏼‍♂️ |
138
+ | 9.g. INCLUDE columns | 🤷🏼‍♂️ |
139
+ | 9.h. CLUSTERED/NONCLUSTERED | 🤷🏼‍♂️ |
140
+ | 9.i. Functional index | ✅ |
141
+ | 9.j. FULLTEXT/SPATIAL index | 🤷🏼‍♂️ |
142
+ | 9.k. COLLATE | ❓ |
143
+ | 9.l. COMMENT | ❓ |
144
+ | 9.m. NULLS LAST/FIRST | 🤷🏼‍♂️ |
145
+ | 9.n. ASC/DESC | ❓ |
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 | ❌ |
@@ -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 no-param-reassign */ /* eslint-disable consistent-return */ /* 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 COMMAND_KIND = {
40
40
  REF: 'ref'
41
41
  };
@@ -982,7 +982,6 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
982
982
  {
983
983
  if (cmd.value.columns.length === 0) break;
984
984
  if (!(cmd.value.pk || cmd.value.unique)) break;
985
- // eslint-disable-next-line prefer-destructuring
986
985
  kind = cmd.kind;
987
986
  var _table2 = findTable(_this8.data.tables, schemaName, tableName);
988
987
  if (!_table2) break;
@@ -1407,7 +1406,7 @@ var PostgresASTGen = exports["default"] = /*#__PURE__*/function (_PostgreSQLPars
1407
1406
  // undefined,
1408
1407
  // { type_name: 'TIMESTAMPTZ', schemaName: null }
1409
1408
  // ]
1410
- // eslint-disable-next-line no-unused-vars
1409
+
1411
1410
  var _expressionValueSet = _slicedToArray(expressionValueSet, 3),
1412
1411
  rawValue = _expressionValueSet[0],
1413
1412
  _ = _expressionValueSet[1],
@@ -0,0 +1,157 @@
1
+ # PostgreSQL model structure generator
2
+
3
+ This folder houses the implementation of the PostgreSQL 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 PostgreSQL.
10
+ - ❓: Valid SQL in PostgreSQL, the generator can still generate output but it ignores this syntax.
11
+ - ❌: Valid SQL in PostgreSQL, but the generator fails to generate any output.
12
+
13
+ | SQL syntax | PostgreSQL |
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 | ❓ (ignore the RETURNING clause) |
22
+ | 1.g. INSERT ... ON CONFLICT (UPSERT)/INSERT ... ON DUPLICATE KEY/INSERT … IGNORE | ❓ (ignore the ON CONFLICT clause) |
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 | 🤷🏼‍♂️ |
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 | 🤷🏼‍♂️ (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 | 🤷🏼‍♂️ |
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 | ✅ (extraneous increment) |
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 | ❓ (No indication of temporary table) |
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 | ❌ (unsupported for 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 | ✅ (ignore name) |
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 | ❓ (ignore) |
137
+ | 9.f. BTREE/HASH/GIST/BRIN/… index | ✅ |
138
+ | 9.g. INCLUDE columns | ❓ (ignore) |
139
+ | 9.h. CLUSTERED/NONCLUSTERED | 🤷🏼‍♂️ |
140
+ | 9.i. Functional index | ✅ |
141
+ | 9.j. FULLTEXT/SPATIAL index | 🤷🏼‍♂️ |
142
+ | 9.k. COLLATE | ❓ (ignore) |
143
+ | 9.l. COMMENT | ❓ (ignore) |
144
+ | 9.m. NULLS LAST/FIRST | ❓ (ignore) |
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 | ❓ (ignore) |
@@ -0,0 +1,157 @@
1
+ # Snowflake model structure generator
2
+
3
+ This folder houses the implementation of the Snowflake 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 Snowflake.
10
+ - ❓: Valid SQL in Snowflake, the generator can still generate output but it ignores this syntax.
11
+ - ❌: Valid SQL in Snowflake, but the generator fails to generate any output.
12
+
13
+ | SQL syntax | Snowflake |
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 | 🤷🏼‍♂️ |
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 | ❌ (weird error: (undefined:undefined) undefined) |
39
+ | 6.c.ii. Out-of-line FOREIGN KEY | ❌ (weird error: (undefined:undefined) undefined) |
40
+ | 6.c.iii. Composite FOREIGN KEY | ❌ (weird error: (undefined:undefined) undefined) |
41
+ | 6.c.iv. Named FOREIGN KEY | ❌ (weird error: (undefined:undefined) undefined) |
42
+ | 6.c.v. ON UPDATE | ❌ (weird error: (undefined:undefined) undefined) |
43
+ | 6.c.vi. ON DELETE | ❌ (weird error: (undefined:undefined) undefined) |
44
+ | 6.c.vii. Other options (deferrable, etc.) | ❌ (weird error: (undefined:undefined) undefined) |
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 | ❌ (parse fail) |
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 | 🤷🏼‍♂️ |
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 | 🤷🏼‍♂️ |
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 | ✅ (only for IDENTITY()) |
84
+ | 6.j.v. GENERATED ... AS IDENTITY | ❌ (parse fail) |
85
+ | 6.k. Computed column | ❓ |
86
+ | 6.l. TEMPORARY tables | ❓ (No indication of temporary table) |
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 | ❌ |
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 | ❓ (ignore name) |
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 | ❓ (ignore name) |
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 | 🤷🏼‍♂️ |
137
+ | 9.f. BTREE/HASH/GIST/BRIN/… index | 🤷🏼‍♂️ |
138
+ | 9.g. INCLUDE columns | 🤷🏼‍♂️ |
139
+ | 9.h. CLUSTERED/NONCLUSTERED | 🤷🏼‍♂️ |
140
+ | 9.i. Functional index | 🤷🏼‍♂️ |
141
+ | 9.j. FULLTEXT/SPATIAL index | 🤷🏼‍♂️ |
142
+ | 9.k. COLLATE | 🤷🏼‍♂️ |
143
+ | 9.l. COMMENT | 🤷🏼‍♂️ |
144
+ | 9.m. NULLS LAST/FIRST | 🤷🏼‍♂️ |
145
+ | 9.n. ASC/DESC | 🤷🏼‍♂️ |
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 | 🤷🏼‍♂️ |
@@ -32,7 +32,7 @@ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError(
32
32
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
33
33
  function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
34
34
  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); }
35
- 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 */
35
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
36
36
  var sanitizeComment = function sanitizeComment(stringContext) {
37
37
  return (0, _helpers.getOriginalText)(stringContext).replace(/''/g, "'").slice(1, -1);
38
38
  };
@@ -1,3 +1,5 @@
1
+ /* WARNING - MUST READ: Before updating the grammar, check for all the MUST READ below*/
2
+
1
3
  /*
2
4
  Original: https://github.com/antlr/grammars-v4/blob/master/sql/mysql/Positive-Technologies/MySqlLexer.g4
3
5
  Last updated: 2023-12-05
@@ -35,6 +37,8 @@ THE SOFTWARE.
35
37
  lexer grammar MySqlLexer;
36
38
 
37
39
  options {
40
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
41
+ superClass = MySqlLexerBase;
38
42
  caseInsensitive = true;
39
43
  }
40
44
 
@@ -43,6 +47,45 @@ channels {
43
47
  ERRORCHANNEL
44
48
  }
45
49
 
50
+ TRANSITION_TO_HIGH_PRIORITY: {true}? -> mode(HIGH_PRIORITY_MODE), skip;
51
+
52
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
53
+ // Why do we need to do this
54
+ // Consider:
55
+ // ```
56
+ // DELIMITER '
57
+ // CREATE TABLE Users (
58
+ // id INT
59
+ // )' -- first quote
60
+ // CREATE TABLE Posts (
61
+ // id INT
62
+ // )' -- second quote
63
+ // ```
64
+ // The Lexer grammar itself wouldn't work because
65
+ // ANTLR prioritizes the longest match first, which would be a string literal.
66
+ // So the first quote wouldn't be treated as a STATEMENT_TERMINATOR,
67
+ // but rather the WHOLE string from the first quote to the second quote is treated as a STRING LITERAL
68
+ // Therefore, we split into two modes: high-priority and low-priority
69
+ mode HIGH_PRIORITY_MODE;
70
+ // SEMI should be preferred over STATEMENT_TERMINATOR, as:
71
+ // - Procedural SQL still uses SEMI regardless of the current STATEMENT_TERMINATOR
72
+ // - If SEMI is below STATEMENT_TERMINATOR, then by default, ';' will never be lexed as a SEMI token
73
+ // Note that this requires the parser to account for both STATEMENT_TERMINATOR
74
+ SEMI : ';';
75
+
76
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
77
+ STATEMENT_TERMINATOR: ~[ \t\r\n]+ {this.isCurrentDelimiter(this.text)}?;
78
+
79
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
80
+ TRANSITION_TO_LOW_PRIORITY: {true}? -> mode(LOW_PRIORITY_MODE), skip;
81
+
82
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
83
+ mode LOW_PRIORITY_MODE;
84
+
85
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
86
+ // DELIMITER - should override other symbols
87
+ DELIMITER_KEYWORD : 'DELIMITER' [ \t\r\n]+ -> mode(DELIMITER_MODE), skip;
88
+
46
89
  // SKIP
47
90
 
48
91
  SPACE : [ \t\r\n]+ -> channel(HIDDEN);
@@ -1244,7 +1287,6 @@ DOT : '.';
1244
1287
  LR_BRACKET : '(';
1245
1288
  RR_BRACKET : ')';
1246
1289
  COMMA : ',';
1247
- SEMI : ';';
1248
1290
  AT_SIGN : '@';
1249
1291
  ZERO_DECIMAL : '0';
1250
1292
  ONE_DECIMAL : '1';
@@ -1354,4 +1396,20 @@ fragment IP_ADDRESS : [0-9]+ '.' [0-9.]+ | [0-9A-F]* ':' [0-9A-F]* ':' [0
1354
1396
 
1355
1397
  // Last tokens must generate Errors
1356
1398
 
1357
- ERROR_RECONGNIGION: . -> channel(ERRORCHANNEL);
1399
+ ERROR_RECONGNIGION: . -> channel(ERRORCHANNEL);
1400
+
1401
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
1402
+ // DELIMITER mode
1403
+ mode DELIMITER_MODE;
1404
+
1405
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
1406
+ NEW_DELIMITER
1407
+ : ~[ \t\r\n]+
1408
+ {
1409
+ this.setDelimiter(this.text);
1410
+ }
1411
+ -> mode(HIGH_PRIORITY_MODE), skip
1412
+ ;
1413
+
1414
+ // MUST READ: This is used to detect dynamic DELIMITERs, the original grammar does not have this
1415
+ DELIMITER_WS: [ \t\r\n]+ -> skip;