@dbml/core 5.3.1 → 5.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @dbml/core
2
2
 
3
- See our website [@dbml/core](https://dbml.dbdiagram.io/js-module/core) for more information
3
+ Refer to [@dbml/core](https://dbml.dbdiagram.io/js-module/core) for the complete API reference.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,3 +10,203 @@ npm install @dbml/core
10
10
  # or if you're using yarn
11
11
  yarn add @dbml/core
12
12
  ```
13
+
14
+ ## SQL Parser Feature Support
15
+
16
+ This section documents the SQL parsing capabilities for each supported database when importing SQL to DBML.
17
+
18
+ For more detailed documentation on each SQL parser, see the individual parser READMEs:
19
+ - [PostgreSQL Parser](./src/parse/ANTLR/ASTGeneration/postgres/README.md)
20
+ - [MySQL Parser](./src/parse/ANTLR/ASTGeneration/mysql/README.md)
21
+ - [MSSQL Parser](./src/parse/ANTLR/ASTGeneration/mssql/README.md)
22
+ - [Oracle Parser](./src/parse/ANTLR/ASTGeneration/oraclesql/README.md)
23
+ - [Snowflake Parser](./src/parse/ANTLR/ASTGeneration/snowflake/README.md)
24
+
25
+ ### Support Legend
26
+
27
+ | Symbol | Meaning |
28
+ |--------|---------|
29
+ | ✓ | Fully supported and correctly parsed |
30
+ | ◐ | Valid SQL that is parsed, but some options/clauses are ignored |
31
+ | ✗ | Valid SQL syntax, but the parser fails to generate output |
32
+ | — | Syntax not valid for this database |
33
+
34
+ ### `CREATE TABLE`
35
+
36
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
37
+ |---------|------------|-------|-------|--------|-----------|
38
+ | Basic syntax | ✓ | ✓ | ✓ | ✓ | ✓ |
39
+ | Parameterized types (e.g., `VARCHAR(255)`) | ✓ | ✓ | ✓ | ✓ | ✓ |
40
+ | Array types (e.g., `INTEGER[]`) | ✓ | — | — | — | — |
41
+ | Enumerated types (`ENUM`) | ✓ | ✓ | — | — | — |
42
+ | Temporary tables | ◐ | ✗ | ✓ | ◐ | ◐ |
43
+ | `CREATE TABLE` AS SELECT | ✗ | ✗ | ✗ | ✗ | ✗ |
44
+ | Table options (`ENGINE`, `TABLESPACE`, etc.) | ◐ | ◐ | ◐ | ◐ | ◐ |
45
+ | Other column properties (`COLLATE`, etc.) | ◐ | ✗ | ◐ | ◐ | ◐ |
46
+ | Generated/Computed columns | ◐ | ◐ | ◐ | ◐ | ◐ |
47
+
48
+ **Notes:**
49
+ - **MSSQL**:
50
+ - Temporary tables use `#` prefix (local) and `##` prefix (global)
51
+ - Square bracket identifiers (`[identifier]`) are supported
52
+
53
+ #### `PRIMARY KEY`
54
+
55
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
56
+ |---------|------------|-------|-------|--------|-----------|
57
+ | Column-level | ✓ | ✓ | ✓ | ✓ | ✓ |
58
+ | Table-level | ✓ | ✓ | ✓ | ✓ | ✓ |
59
+ | Multi-column | ✓ | ✓ | ✓ | ✓ | ✓ |
60
+ | Explicitly named (`CONSTRAINT name`) | ✓ | ✓ | ✓ | ✓ | ✓ |
61
+ | CLUSTERED/NONCLUSTERED | — | — | ◐ | — | — |
62
+
63
+ #### `FOREIGN KEY`
64
+
65
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
66
+ |---------|------------|-------|-------|--------|-----------|
67
+ | Column-level (`REFERENCES`) | ✓ | ✓ | ✗ | ✓ | ✗ |
68
+ | Table-level | ✓ | ✓ | ✓ | ✓ | ✗ |
69
+ | Multi-column | ✓ | ✓ | ✓ | ✓ | ✗ |
70
+ | Explicitly named (`CONSTRAINT name`) | ✓ | ✓ | ✓ | ✓ | ✗ |
71
+ | `ON UPDATE` action | ✓ | ✓ | ✓ | — | ✗ |
72
+ | `ON DELETE` action | ✓ | ✓ | ✓ | ✓ | ✗ |
73
+
74
+ **Notes:**
75
+ - **MSSQL**: Column-level `FOREIGN KEY` has a known bug - use table-level syntax instead
76
+ - **Snowflake**: All `FOREIGN KEY` definitions have a known bug producing undefined errors
77
+
78
+ #### `UNIQUE`
79
+
80
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
81
+ |---------|------------|-------|-------|--------|-----------|
82
+ | Column-level | ✓ | ✓ | ✓ | ✓ | ✓ |
83
+ | Table-level | ✓ | ✓ | ✓ | ✓ | ✓ |
84
+ | Multi-column | ✓ | ✓ | ✓ | ✓ | ✓ |
85
+ | Explicitly named (`CONSTRAINT name`) | ✓ | ✓ | ◐ | ✓ | ◐ |
86
+ | `UNIQUE KEY`/`UNIQUE INDEX` syntax | — | ✓ | — | — | — |
87
+
88
+ #### `CHECK`
89
+
90
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
91
+ |---------|------------|-------|-------|--------|-----------|
92
+ | Column-level | ✓ | ✓ | ✓ | ✓ | ✗ |
93
+ | Table-level | ✓ | ✓ | ✓ | ✓ | ✗ |
94
+ | Explicitly named (`CONSTRAINT name`) | ✓ | ✓ | ✓ | ✓ | ✗ |
95
+
96
+ #### `DEFAULT`
97
+
98
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
99
+ |---------|------------|-------|-------|--------|-----------|
100
+ | Column-level | ✓ | ✓ | ✓ | ✓ | ✓ |
101
+ | Function as default | ✓ | ✓ | ✓ | ✓ | ✓ |
102
+ | Explicitly named (`CONSTRAINT name`) | — | — | ◐ | — | ◐ |
103
+
104
+ #### `NOT NULL`
105
+
106
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
107
+ |---------|------------|-------|-------|--------|-----------|
108
+ | Column-level `NOT NULL` | ✓ | ✓ | ✓ | ✓ | ✓ |
109
+ | Explicit column-level `NULL` | ✓ | ✓ | ✓ | ✓ | ✓ |
110
+
111
+ #### Auto-Increment Columns
112
+
113
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
114
+ |---------|------------|-------|-------|--------|-----------|
115
+ | `SERIAL` (pseudo-type) | ✓ | — | — | — | — |
116
+ | `BIGSERIAL` (pseudo-type) | ✓ | — | — | — | — |
117
+ | `AUTO_INCREMENT` (column attribute) | — | ✓ | — | — | — |
118
+ | `IDENTITY(seed, increment)` (column property) | — | — | ✓ | — | ✓ |
119
+ | `GENERATED AS IDENTITY` (column property) | ✓ | — | ✗ | ✓ | ✗ |
120
+ | `GENERATED ALWAYS AS IDENTITY` | ✓ | — | — | ✓ | — |
121
+ | `GENERATED BY DEFAULT AS IDENTITY` | ✓ | — | — | ✓ | — |
122
+
123
+ #### Inline Indexes
124
+
125
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
126
+ |---------|------------|-------|-------|--------|-----------|
127
+ | Column-level indexes | — | ✗ | — | — | — |
128
+ | Table-level `INDEX`/`KEY` | — | ✓ | — | ✓ | — |
129
+ | Named indexes | — | ✓ | — | ✓ | — |
130
+ | Multi-column indexes | — | ✓ | — | ✓ | — |
131
+ | USING BTREE/HASH | — | ✓ | — | — | — |
132
+ | FULLTEXT/SPATIAL | — | ◐ | — | — | — |
133
+
134
+ ---
135
+
136
+ ### `CREATE INDEX`
137
+
138
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
139
+ |---------|------------|-------|-------|--------|-----------|
140
+ | Basic `CREATE INDEX` | ✓ | ✓ | ✓ | ✓ | — |
141
+ | Multi-column index | ✓ | ✓ | ✓ | ✓ | — |
142
+ | `UNIQUE` index | ✓ | ✓ | ✓ | ✓ | — |
143
+ | Function-based index | ✓ | ✓ | — | ✓ | — |
144
+ | BTREE | ✓ | ✓ | ✗ | — | — |
145
+ | HASH | ✓ | ✓ | — | — | — |
146
+ | GIST | ✓ | — | — | — | — |
147
+ | BRIN | ✓ | — | — | — | — |
148
+ | GIN | ✓ | — | — | — | — |
149
+ | Partial/Filtered index (`WHERE`) | ◐ | ✗ | ◐ | ◐ | — |
150
+ | FULLTEXT | — | ◐ | ✗ | — | — |
151
+ | SPATIAL | — | ◐ | ✗ | — | — |
152
+
153
+ **Notes:**
154
+ - **MSSQL**: Function-based indexes use computed columns instead
155
+
156
+ ---
157
+
158
+ ### `INSERT` Statements
159
+
160
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
161
+ |---------|------------|-------|-------|--------|-----------|
162
+ | Basic `INSERT` ... VALUES | ✓ | ✓ | ✓ | ✓ | ✗ |
163
+ | Multi-row `INSERT` | ✓ | ✓ | ✓ | — | ✓ |
164
+ | `INSERT` ... SELECT | ✗ | ✗ | ✗ | ✗ | ✗ |
165
+ | `INSERT` ... with returned rows (`RETURNING`, `OUTPUT`) | ◐ | — | ◐ | ◐ | — |
166
+ | `INSERT` ... ON CONFLICT/DUPLICATE KEY | ◐ | ◐ | — | — | — |
167
+
168
+ **Notes:**
169
+ - **Oracle**: Uses `INSERT ALL` syntax for multi-row inserts (not supported)
170
+
171
+ ---
172
+
173
+ ### `ALTER TABLE`
174
+
175
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
176
+ |---------|------------|-------|-------|--------|-----------|
177
+ | **ADD COLUMN** | ✗ | ✗ | ✗ | ✗ | ✗ |
178
+ | **DROP COLUMN** | ✗ | ✗ | ✗ | ✗ | ✗ |
179
+ | **ALTER/MODIFY COLUMN** | ✗ | ✗ | ✗ | ✗ | ✗ |
180
+ | **RENAME COLUMN** | ✗ | ✗ | ✗ | ✗ | ✗ |
181
+ | **ADD CONSTRAINT** | | | | | |
182
+ | - `DEFAULT` | ✗ | ✗ | ✓ | ✓ | ✗ |
183
+ | - `NOT NULL` | ✗ | ✗ | ✗ | ✓ | ✗ |
184
+ | - `CHECK` | ✓ | ✓ | ✓ | ✓ | — |
185
+ | - `UNIQUE` | ✓ | ✗ | ✓ | ✓ | ✓ |
186
+ | - `PRIMARY KEY` | ✓ | ✓ | ✓ | ✓ | ✗ |
187
+ | - `FOREIGN KEY` | ✓ | ✓ | ✓ | ✓ | ✓ |
188
+ | **DROP CONSTRAINT** | ✗ | ✗ | ✗ | ✗ | ✗ |
189
+
190
+ ---
191
+
192
+ ### Comments
193
+
194
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
195
+ |---------|------------|-------|-------|--------|-----------|
196
+ | Table comments | ✓ | ✓ | ◐ | ✓ | ✓ |
197
+ | Column comments | ✓ | ✓ | ◐ | ✓ | ✗ |
198
+ | Comment syntax | `COMMENT ON` | Inline `COMMENT` | `sp_addextendedproperty` | `COMMENT ON` | Inline `COMMENT` |
199
+
200
+ **Notes:**
201
+ - **MSSQL**: Comments via `sp_addextendedproperty` have unreliable parsing
202
+
203
+ ---
204
+
205
+ ### Other DDL Statements
206
+
207
+ | Feature | PostgreSQL | MySQL | MSSQL | Oracle | Snowflake |
208
+ |---------|------------|-------|-------|--------|-----------|
209
+ | `DROP TABLE` | ✗ | ✗ | ✗ | ✗ | ✗ |
210
+ | `DROP INDEX` | ✗ | ✗ | ✗ | ✗ | — |
211
+ | `ALTER INDEX` | ✗ | — | ✗ | ✗ | — |
212
+ | `CREATE VIEW` | ✗ | ✗ | ✗ | ✗ | ✗ |
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _lodash = require("lodash");
8
+ var _parse = require("@dbml/parse");
8
9
  var _utils = require("./utils");
9
10
  var _config = require("../model_structure/config");
10
11
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
@@ -224,6 +225,9 @@ var DbmlExporter = /*#__PURE__*/function () {
224
225
  // Include schema name if needed
225
226
  var tableName = "\"".concat(table.name, "\"");
226
227
  if ((0, _utils.shouldPrintSchema)(schema, model)) tableName = "\"".concat(schema.name, "\".\"").concat(table.name, "\"");
228
+
229
+ // Include alias if present
230
+ var aliasStr = table.alias ? " as ".concat((0, _parse.addQuoteIfNeeded)(table.alias)) : '';
227
231
  var fieldStr = tableContent.fieldContents.map(function (field) {
228
232
  return " ".concat(field, "\n");
229
233
  }).join('');
@@ -242,7 +246,7 @@ var DbmlExporter = /*#__PURE__*/function () {
242
246
  indexStr = "\n Indexes {\n".concat(indexBody, " }\n");
243
247
  }
244
248
  var noteStr = table.note ? " Note: ".concat(DbmlExporter.escapeNote(table.note), "\n") : '';
245
- return "Table ".concat(tableName).concat(tableSettingStr, " {\n").concat(fieldStr).concat(checkStr).concat(indexStr).concat(noteStr, "}\n");
249
+ return "Table ".concat(tableName).concat(aliasStr).concat(tableSettingStr, " {\n").concat(fieldStr).concat(checkStr).concat(indexStr).concat(noteStr, "}\n");
246
250
  });
247
251
  return tableStrs.length ? tableStrs.join('\n') : '';
248
252
  }
package/lib/index.js CHANGED
@@ -39,10 +39,17 @@ Object.defineProperty(exports, "importer", {
39
39
  return _import["default"];
40
40
  }
41
41
  });
42
+ Object.defineProperty(exports, "renameTable", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _transform.renameTable;
46
+ }
47
+ });
42
48
  var _ModelExporter = _interopRequireDefault(require("./export/ModelExporter"));
43
49
  var _Parser = _interopRequireDefault(require("./parse/Parser"));
44
50
  var _error = require("./parse/error");
45
51
  var _import = _interopRequireDefault(require("./import"));
46
52
  var _export = _interopRequireDefault(require("./export"));
53
+ var _transform = require("./transform");
47
54
  var _version = require("./utils/version");
48
55
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }