@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.
@@ -1,157 +1,236 @@
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 | 🤷🏼‍♂️ |
1
+ # Snowflake SQL Parser Support
2
+
3
+ > Comprehensive documentation for the Snowflake model structure generator based on the ANTLR4 parser.
4
+
5
+ ## Overview
6
+
7
+ This module provides SQL parsing capabilities for Snowflake databases, enabling conversion of Snowflake DDL statements to DBML format. The parser supports Snowflake-specific syntax including `IDENTITY` columns with increment ranges. Note that Snowflake, as a cloud data warehouse, does not support traditional indexes, and the parser has known issues with `FOREIGN KEY` and `CHECK` constraints.
8
+
9
+ ## Support Legend
10
+
11
+ | Symbol | Meaning |
12
+ |--------|---------|
13
+ | | Fully supported and correctly parsed |
14
+ | ◐ | Valid SQL that is parsed, but some options/clauses are ignored |
15
+ | | Valid Snowflake syntax, but the parser fails to generate output |
16
+ | | Syntax not valid in Snowflake |
17
+
18
+ ## Key Capabilities
19
+
20
+ - **Data Definition**
21
+ - `CREATE TABLE` with basic syntax support
22
+ - Data types: parameterized types (e.g., `VARCHAR(255)`, `NUMBER(10,2)`)
23
+ - **Constraints**
24
+ - `PRIMARY KEY` (column-level, table-level, multi-column, with explicit name)
25
+ - `UNIQUE` (column-level, table-level, multi-column)
26
+ - `DEFAULT`, `NOT NULL`
27
+ - `FOREIGN KEY`: **Not Supported** (known bug)
28
+ - `CHECK`: **Not Supported** (parse failure)
29
+ - **Auto-increment**
30
+ - `IDENTITY` with increment range (e.g., `IDENTITY(1,1)`)
31
+ - **Indexes**
32
+ - N/A (Snowflake does not support user-defined indexes)
33
+ - **Comments**
34
+ - Table comments only (column comments not supported)
35
+ - **Data Manipulation**
36
+ - Multi-row `INSERT` only
37
+
38
+ ---
39
+
40
+ ## Feature Support Matrix
41
+
42
+ ### `CREATE TABLE`
43
+
44
+ | Feature | Status | Notes |
45
+ |---------|---------|-------|
46
+ | Basic `CREATE TABLE` syntax | | |
47
+ | Enumerated data types | | Not supported in Snowflake |
48
+ | Parameterized types `name(...)` | | e.g., `VARCHAR(255)`, `NUMBER(10,2)` |
49
+ | Array types `name[...]` | | Snowflake uses ARRAY type differently |
50
+ | TEMPORARY tables | | Parsed but no indication of temporary status |
51
+ | `CREATE TABLE` AS SELECT | | |
52
+ | Table options (CLUSTER BY, etc.) | | Options are ignored |
53
+
54
+ ### Constraints
55
+
56
+ #### `PRIMARY KEY`
57
+
58
+ | Feature | Status | Notes |
59
+ |---------|---------|-------|
60
+ | Column-level `PRIMARY KEY` | | `id INT PRIMARY KEY` |
61
+ | Table-level `PRIMARY KEY` | | `PRIMARY KEY (id)` |
62
+ | Multi-column `PRIMARY KEY` | | `PRIMARY KEY (a, b)` |
63
+ | Explicitly named (CONSTRAINT name) | | `CONSTRAINT pk_name PRIMARY KEY (id)` |
64
+ | RELY / NORELY options || Constraint enforcement hints are ignored |
65
+
66
+ #### `FOREIGN KEY`
67
+
68
+ | Feature | Status | Notes |
69
+ |---------|---------|-------|
70
+ | Column-level `FOREIGN KEY` | | Known bug - produces undefined error |
71
+ | Table-level `FOREIGN KEY` | | Known bug - produces undefined error |
72
+ | Multi-column `FOREIGN KEY` | | Known bug - produces undefined error |
73
+ | Explicitly named (CONSTRAINT name) | | Known bug - produces undefined error |
74
+ | `ON UPDATE` action | | Known bug - produces undefined error |
75
+ | `ON DELETE` action | | Known bug - produces undefined error |
76
+ | Constraint options | | Known bug - produces undefined error |
77
+
78
+ #### `UNIQUE`
79
+
80
+ | Feature | Status | Notes |
81
+ |---------|---------|-------|
82
+ | Column-level `UNIQUE` | | `col INT UNIQUE` |
83
+ | Table-level `UNIQUE` | | `UNIQUE (col)` |
84
+ | Multi-column `UNIQUE` | | `UNIQUE (a, b)` |
85
+ | Explicitly named (CONSTRAINT name) | | Name is ignored in output |
86
+ | Constraint options | | Options are ignored |
87
+ | NULLS NOT DISTINCT | | Not valid in Snowflake |
88
+ | `UNIQUE KEY`/`UNIQUE INDEX` || MySQL syntax - not valid in Snowflake |
89
+
90
+ #### `CHECK`
91
+
92
+ | Feature | Status | Notes |
93
+ |---------|---------|-------|
94
+ | Column-level `CHECK` | | `CHECK (col > 0)` - parse failure |
95
+ | Table-level `CHECK` | | Parse failure |
96
+ | Explicitly named (CONSTRAINT name) | | Parse failure |
97
+ | Enforcement options | | Parse failure |
98
+
99
+ #### `DEFAULT`
100
+
101
+ | Feature | Status | Notes |
102
+ |---------|---------|-------|
103
+ | Column-level `DEFAULT` | | `col INT DEFAULT 0` |
104
+ | Table-level `DEFAULT` | | Parse failure |
105
+ | Function as `DEFAULT` | | `DEFAULT CURRENT_TIMESTAMP()` |
106
+ | Explicitly named `DEFAULT` | | Name is ignored in output |
107
+
108
+ #### `NOT NULL` / NULL
109
+
110
+ | Feature | Status | Notes |
111
+ |---------|---------|-------|
112
+ | Column-level `NOT NULL` | | |
113
+ | NULL attribute | | |
114
+ | Table-level `NOT NULL` | | |
115
+ | Constraint options | | Options are ignored |
116
+
117
+ ### Auto-Increment Columns
118
+
119
+ | Feature | Status | Notes |
120
+ |---------|---------|-------|
121
+ | `IDENTITY` (column property) | | `id INT IDENTITY(1,1)` |
122
+ | Increment range | | `IDENTITY(start, increment)` syntax |
123
+ | `AUTO_INCREMENT` (column attribute) | | MySQL syntax - not valid in Snowflake |
124
+ | `SERIAL` (pseudo-type) | | PostgreSQL syntax - not valid in Snowflake |
125
+ | `BIGSERIAL` (pseudo-type) | | PostgreSQL syntax - not valid in Snowflake |
126
+ | `GENERATED AS IDENTITY` (column property) | | SQL standard syntax - parse failure |
127
+
128
+ ### Inline Indexes (in `CREATE TABLE`)
129
+
130
+ | Feature | Status | Notes |
131
+ |---------|---------|-------|
132
+ | All index features | | Snowflake does not support user-defined indexes |
133
+
134
+ ### Table/Column Comments (in `CREATE TABLE`)
135
+
136
+ | Feature | Status | Notes |
137
+ |---------|---------|-------|
138
+ | Table `COMMENT` attribute | | |
139
+ | Column `COMMENT` attribute | | |
140
+
141
+ ---
142
+
143
+ ### `CREATE INDEX`
144
+
145
+ | Feature | Status | Notes |
146
+ |---------|---------|-------|
147
+ | All index features | | Snowflake does not support `CREATE INDEX` |
148
+
149
+ ---
150
+
151
+ ### `INSERT` Statements
152
+
153
+ | Feature | Status | Notes |
154
+ |---------|---------|-------|
155
+ | Basic `INSERT` ... VALUES | | |
156
+ | Multi-row `INSERT` | | |
157
+ | `INSERT` ... SELECT | | |
158
+ | WITH clause (CTE) | ✗ | |
159
+ | Target table alias | — | |
160
+ | `INSERT` ... RETURNING | — | |
161
+ | `INSERT` OVERWRITE | ✗ | |
162
+ | Multi-table `INSERT` | ✗ | |
163
+ | Conditional `INSERT` (WHEN/FIRST/ALL) | ✗ | |
164
+
165
+ ---
166
+
167
+ ### `ALTER TABLE`
168
+
169
+ | Feature | Status | Notes |
170
+ |---------|---------|-------|
171
+ | **ADD COLUMN** | | |
172
+ | - All column properties | ✗ | |
173
+ | **DROP COLUMN** | ✗ | |
174
+ | **ALTER COLUMN / MODIFY** | | |
175
+ | - `COMMENT` | ✗ | |
176
+ | - Other modifications | ✗ | |
177
+ | **RENAME COLUMN** | ✗ | |
178
+ | **ADD CONSTRAINT** | | |
179
+ | - Named `CHECK` | — | Snowflake uses SET/UNSET for constraints |
180
+ | - Unnamed `CHECK` | — | |
181
+ | - Named `UNIQUE` | ◐ | Name is ignored |
182
+ | - Unnamed `UNIQUE` | ✓ | |
183
+ | - Named `PRIMARY KEY` | ✗ | |
184
+ | - Unnamed `PRIMARY KEY` | ✗ | |
185
+ | - Named `FOREIGN KEY` | ◐ | Name is ignored |
186
+ | - Unnamed `FOREIGN KEY` | ✓ | |
187
+ | - `DEFAULT` | ✗ | Parse failure |
188
+ | - `NOT NULL` / NULL | ✗ | |
189
+ | **DROP CONSTRAINT** | ✗ | |
190
+ | **ALTER CONSTRAINT** | ✗ | |
191
+ | **RENAME TABLE** | ✗ | |
192
+ | **SET SCHEMA** | ✗ | |
193
+
194
+ ---
195
+
196
+ ### Other DDL Statements
197
+
198
+ | Feature | Status | Notes |
199
+ |---------|---------|-------|
200
+ | `DROP TABLE` | ✗ | |
201
+ | `DROP INDEX` | — | No indexes in Snowflake |
202
+ | `ALTER INDEX` | — | No indexes in Snowflake |
203
+ | `CREATE VIEW` | ✗ | |
204
+
205
+ ---
206
+
207
+ ### Comments (Standalone Statements)
208
+
209
+ | Feature | Status | Notes |
210
+ |---------|---------|-------|
211
+ | `COMMENT ON TABLE` | ✗ | |
212
+ | `COMMENT ON COLUMN` | ✗ | |
213
+ | COMMENT ... IS NULL | — | Use `ALTER TABLE ... SET/UNSET COMMENT` |
214
+
215
+ ---
216
+
217
+ ## Known Limitations
218
+
219
+ - **`FOREIGN KEY` constraints**: All `FOREIGN KEY` definitions fail with undefined errors
220
+ - **`CHECK` constraints**: All `CHECK` constraint definitions fail to parse
221
+ - **Column comments**: Column-level comments are not supported
222
+ - **Basic `INSERT`**: Single-row `INSERT` without parentheses may fail; use multi-row `INSERT` syntax
223
+ - **`ALTER TABLE` operations**: Very limited support
224
+ - **`CREATE VIEW`**: View definitions are not parsed
225
+ - **Indexes**: Not applicable to Snowflake (cloud DW architecture)
226
+ - **`GENERATED AS IDENTITY`**: SQL standard syntax not supported; use `IDENTITY(start, increment)` instead
227
+
228
+ ## Snowflake-Specific Notes
229
+
230
+ 1. **`IDENTITY` Columns**: Snowflake uses `IDENTITY(start, increment)` syntax for auto-increment, e.g., `IDENTITY(1,1)`. This is supported with increment range
231
+ 2. **No Indexes**: Snowflake is a cloud data warehouse that does not support traditional indexes. All index-related features are marked N/A
232
+ 3. **`FOREIGN KEY` Issues**: There is a known bug where all `FOREIGN KEY` constraint definitions produce `(undefined:undefined) undefined` errors
233
+ 4. **`CHECK` Constraints**: `CHECK` constraints are valid in Snowflake SQL but currently fail to parse
234
+ 5. **Comments**: Use inline `COMMENT` in `CREATE TABLE` for table comments. Column comments have parsing issues
235
+ 6. **Data Types**: Snowflake has its own type system; common types like `VARCHAR`, `NUMBER`, `TIMESTAMP` are fully supported
236
+ 7. **Constraint Enforcement**: Snowflake's constraint options like `RELY`/`NORELY`, `ENFORCED`/`NOT ENFORCED` are parsed but ignored
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.renameTable = renameTable;
7
+ var _parse = require("@dbml/parse");
8
+ /**
9
+ * Renames a table in DBML code using symbol table and token-based replacement.
10
+ *
11
+ * @param {string | { schema?: string; table: string }} oldName - The current table name
12
+ * @param {string | { schema?: string; table: string }} newName - The new table name
13
+ * @param {string} dbmlCode - The DBML code containing the table
14
+ * @returns {string} The updated DBML code with the renamed table
15
+ *
16
+ * @example
17
+ * // String format
18
+ * renameTable('users', 'customers', dbmlCode);
19
+ * renameTable('public.users', 'auth.customers', dbmlCode);
20
+ *
21
+ * @example
22
+ * // Object format
23
+ * renameTable({ table: 'users' }, { table: 'customers' }, dbmlCode);
24
+ * renameTable({ schema: 'auth', table: 'users' }, { schema: 'auth', table: 'customers' }, dbmlCode);
25
+ */
26
+ function renameTable(oldName, newName, dbmlCode) {
27
+ var compiler = new _parse.Compiler();
28
+ compiler.setSource(dbmlCode);
29
+ return compiler.renameTable(oldName, newName);
30
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/core",
4
- "version": "5.3.1",
4
+ "version": "5.4.1",
5
5
  "description": "> TODO: description",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -25,7 +25,8 @@
25
25
  "access": "public"
26
26
  },
27
27
  "scripts": {
28
- "test": "jest",
28
+ "test": "jest --coverage=false",
29
+ "coverage": "jest --coverage",
29
30
  "benchmark": "jest --projects jest-bench.config.json",
30
31
  "build:lib": "babel src --out-dir lib --copy-files",
31
32
  "build:parser": "npx babel-node src/parse/buildParser.js",
@@ -35,7 +36,7 @@
35
36
  "lint:fix": "eslint --fix ."
36
37
  },
37
38
  "dependencies": {
38
- "@dbml/parse": "^5.3.1",
39
+ "@dbml/parse": "^5.4.1",
39
40
  "antlr4": "^4.13.1",
40
41
  "lodash": "^4.17.15",
41
42
  "parsimmon": "^1.13.0",
@@ -58,22 +59,11 @@
58
59
  "jest": "^29.5.0",
59
60
  "jest-bench": "^29.4.1",
60
61
  "pegjs-require-import": "0.0.6",
62
+ "ts-jest": "^29.4.5",
61
63
  "typescript": "^5.9.3",
62
64
  "typescript-eslint": "^8.46.3"
63
65
  },
64
- "jest": {
65
- "setupFiles": [
66
- "./jestHelpers.js"
67
- ],
68
- "transform": {
69
- "^.+\\.js$": "babel-jest",
70
- "\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
71
- },
72
- "moduleNameMapper": {
73
- "^lodash-es$": "lodash"
74
- }
75
- },
76
- "gitHead": "54ca4861d608adbfc17c86d840c2e663e9c428f9",
66
+ "gitHead": "f5c8bf0c9d95948e3874cfb6cc777f65c4180891",
77
67
  "engines": {
78
68
  "node": ">=16"
79
69
  }
@@ -1,6 +1,6 @@
1
1
  import Database, { NormalizedDatabase } from '../model_structure/database';
2
2
 
3
- export type ExportFormatOption = 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'oracle';
3
+ export declare type ExportFormatOption = 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'oracle';
4
4
  declare class ModelExporter {
5
5
  static export(model: Database | NormalizedDatabase, format: ExportFormatOption, isNormalized?: boolean): string;
6
6
  }
package/types/index.d.ts CHANGED
@@ -2,5 +2,6 @@ import ModelExporter from './export/ModelExporter';
2
2
  import Parser from './parse/Parser';
3
3
  import importer from './import';
4
4
  import exporter from './export';
5
- export { importer, exporter, ModelExporter, Parser };
5
+ import { renameTable } from './transform';
6
+ export { renameTable, importer, exporter, ModelExporter, Parser };
6
7
  export { CompilerDiagnostic, CompilerError as CompilerDiagnostics, EditorPosition, ErrorCode, WarningLevel, } from './parse/error';
@@ -1,7 +1,7 @@
1
1
  import { Compiler } from '@dbml/parse';
2
2
  import Database, { RawDatabase } from '../model_structure/database';
3
3
 
4
- declare type ParseFormat = 'json'
4
+ export declare type ParseFormat = 'json'
5
5
  | 'mysql' | 'mysqlLegacy'
6
6
  | 'postgres' | 'postgresLegacy'
7
7
  | 'dbml' | 'dbmlv2'
@@ -0,0 +1,7 @@
1
+ export type TableNameInput = string | { schema?: string; table: string };
2
+
3
+ export function renameTable(
4
+ oldName: TableNameInput,
5
+ newName: TableNameInput,
6
+ dbmlCode: string
7
+ ): string;