@dbml/core 5.3.1 → 5.4.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 (184) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +201 -1
  3. package/lib/export/DbmlExporter.js +5 -1
  4. package/lib/export/JsonExporter.js +0 -0
  5. package/lib/export/ModelExporter.js +0 -0
  6. package/lib/export/MysqlExporter.js +0 -0
  7. package/lib/export/OracleExporter.js +0 -0
  8. package/lib/export/PostgresExporter.js +0 -0
  9. package/lib/export/README.md +0 -0
  10. package/lib/export/SqlServerExporter.js +0 -0
  11. package/lib/export/index.js +0 -0
  12. package/lib/export/utils.js +0 -0
  13. package/lib/import/index.js +0 -0
  14. package/lib/index.js +7 -0
  15. package/lib/model_structure/check.js +0 -0
  16. package/lib/model_structure/config.js +0 -0
  17. package/lib/model_structure/database.js +0 -0
  18. package/lib/model_structure/dbState.js +0 -0
  19. package/lib/model_structure/element.js +0 -0
  20. package/lib/model_structure/endpoint.js +0 -0
  21. package/lib/model_structure/enum.js +0 -0
  22. package/lib/model_structure/enumValue.js +0 -0
  23. package/lib/model_structure/field.js +0 -0
  24. package/lib/model_structure/indexColumn.js +0 -0
  25. package/lib/model_structure/indexes.js +0 -0
  26. package/lib/model_structure/ref.js +0 -0
  27. package/lib/model_structure/schema.js +0 -0
  28. package/lib/model_structure/stickyNote.js +0 -0
  29. package/lib/model_structure/table.js +0 -0
  30. package/lib/model_structure/tableGroup.js +0 -0
  31. package/lib/model_structure/tablePartial.js +0 -0
  32. package/lib/model_structure/utils.js +0 -0
  33. package/lib/parse/ANTLR/ASTGeneration/AST.js +0 -0
  34. package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +0 -0
  35. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +0 -0
  36. package/lib/parse/ANTLR/ASTGeneration/constants.js +0 -0
  37. package/lib/parse/ANTLR/ASTGeneration/helpers.js +0 -0
  38. package/lib/parse/ANTLR/ASTGeneration/index.js +0 -0
  39. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +0 -0
  40. package/lib/parse/ANTLR/ASTGeneration/mssql/README.md +263 -157
  41. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +0 -0
  42. package/lib/parse/ANTLR/ASTGeneration/mysql/README.md +262 -157
  43. package/lib/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.js +0 -0
  44. package/lib/parse/ANTLR/ASTGeneration/oraclesql/README.md +261 -157
  45. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +0 -0
  46. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +0 -0
  47. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +0 -0
  48. package/lib/parse/ANTLR/ASTGeneration/postgres/README.md +252 -157
  49. package/lib/parse/ANTLR/ASTGeneration/snowflake/README.md +236 -157
  50. package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +0 -0
  51. package/lib/parse/ANTLR/README.md +0 -0
  52. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.g4 +0 -0
  53. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.interp +0 -0
  54. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.js +0 -0
  55. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.tokens +0 -0
  56. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.g4 +0 -0
  57. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.interp +0 -0
  58. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.js +0 -0
  59. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.tokens +0 -0
  60. package/lib/parse/ANTLR/parsers/mssql/TSqlParserVisitor.js +0 -0
  61. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +0 -0
  62. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +0 -0
  63. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +0 -0
  64. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +0 -0
  65. package/lib/parse/ANTLR/parsers/mysql/MySqlLexerBase.js +0 -0
  66. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +0 -0
  67. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +0 -0
  68. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +0 -0
  69. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +0 -0
  70. package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +0 -0
  71. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.g4 +0 -0
  72. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.interp +0 -0
  73. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.js +0 -0
  74. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.tokens +0 -0
  75. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexerBase.js +0 -0
  76. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.g4 +0 -0
  77. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.interp +0 -0
  78. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.js +0 -0
  79. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.tokens +0 -0
  80. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserBase.js +0 -0
  81. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserVisitor.js +0 -0
  82. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +0 -0
  83. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +0 -0
  84. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +0 -0
  85. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +0 -0
  86. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +0 -0
  87. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +0 -0
  88. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +0 -0
  89. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +0 -0
  90. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +0 -0
  91. package/lib/parse/ANTLR/parsers/postgresql/README.md +0 -0
  92. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.g4 +0 -0
  93. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.interp +0 -0
  94. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.js +0 -0
  95. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.tokens +0 -0
  96. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.g4 +0 -0
  97. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.interp +0 -0
  98. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.js +0 -0
  99. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.tokens +0 -0
  100. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParserVisitor.js +0 -0
  101. package/lib/parse/Parser.js +0 -0
  102. package/lib/parse/buildParser.js +0 -0
  103. package/lib/parse/databaseGenerator.js +0 -0
  104. package/lib/parse/dbml/parser.pegjs +0 -0
  105. package/lib/parse/dbmlParser.js +0 -0
  106. package/lib/parse/error.js +0 -0
  107. package/lib/parse/mssql/base_parsers.js +0 -0
  108. package/lib/parse/mssql/column_definition/actions.js +0 -0
  109. package/lib/parse/mssql/column_definition/index.js +0 -0
  110. package/lib/parse/mssql/constraint_definition/actions.js +0 -0
  111. package/lib/parse/mssql/constraint_definition/index.js +0 -0
  112. package/lib/parse/mssql/expression.js +0 -0
  113. package/lib/parse/mssql/fk_definition/actions.js +0 -0
  114. package/lib/parse/mssql/fk_definition/index.js +0 -0
  115. package/lib/parse/mssql/index.js +0 -0
  116. package/lib/parse/mssql/index_definition/actions.js +0 -0
  117. package/lib/parse/mssql/index_definition/index.js +0 -0
  118. package/lib/parse/mssql/keyword_parsers.js +0 -0
  119. package/lib/parse/mssql/keyword_utils.js +0 -0
  120. package/lib/parse/mssql/statements/actions.js +0 -0
  121. package/lib/parse/mssql/statements/index.js +0 -0
  122. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -0
  123. package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -0
  124. package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +0 -0
  125. package/lib/parse/mssql/statements/statement_types/alter_table/index.js +0 -0
  126. package/lib/parse/mssql/statements/statement_types/comments/actions.js +0 -0
  127. package/lib/parse/mssql/statements/statement_types/comments/index.js +0 -0
  128. package/lib/parse/mssql/statements/statement_types/create_index/actions.js +0 -0
  129. package/lib/parse/mssql/statements/statement_types/create_index/index.js +0 -0
  130. package/lib/parse/mssql/statements/statement_types/create_table/actions.js +0 -0
  131. package/lib/parse/mssql/statements/statement_types/create_table/index.js +0 -0
  132. package/lib/parse/mssql/statements/statement_types/index.js +0 -0
  133. package/lib/parse/mssql/utils.js +0 -0
  134. package/lib/parse/mssql/whitespaces.js +0 -0
  135. package/lib/parse/mssqlParser.js +0 -0
  136. package/lib/parse/mysql/parser.pegjs +0 -0
  137. package/lib/parse/mysqlParser.js +0 -0
  138. package/lib/parse/postgresParser.js +0 -0
  139. package/lib/parse/postgresql/Base_rules.pegjs +0 -0
  140. package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +0 -0
  141. package/lib/parse/postgresql/Commands/Commands.pegjs +0 -0
  142. package/lib/parse/postgresql/Commands/Comment.pegjs +0 -0
  143. package/lib/parse/postgresql/Commands/Create_index.pegjs +0 -0
  144. package/lib/parse/postgresql/Commands/Create_table/Create_table.pegjs +0 -0
  145. package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +0 -0
  146. package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +0 -0
  147. package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +0 -0
  148. package/lib/parse/postgresql/Commands/Create_type/Create_type.pegjs +0 -0
  149. package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +0 -0
  150. package/lib/parse/postgresql/Commands/Create_type/Create_type_range.pegjs +0 -0
  151. package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +0 -0
  152. package/lib/parse/postgresql/Expression.pegjs +0 -0
  153. package/lib/parse/postgresql/InitializerUtils.pegjs +0 -0
  154. package/lib/parse/postgresql/Keywords.pegjs +0 -0
  155. package/lib/parse/postgresql/get_parser.js +0 -0
  156. package/lib/parse/postgresql/parser.pegjs +0 -0
  157. package/lib/parse/schemarb/parser.pegjs +0 -0
  158. package/lib/parse/schemarbParser.js +0 -0
  159. package/lib/transform/index.js +30 -0
  160. package/lib/utils/version.js +0 -0
  161. package/package.json +3 -3
  162. package/types/export/ModelExporter.d.ts +0 -0
  163. package/types/export/index.d.ts +0 -0
  164. package/types/import/index.d.ts +0 -0
  165. package/types/index.d.ts +2 -1
  166. package/types/model_structure/check.d.ts +0 -0
  167. package/types/model_structure/database.d.ts +0 -0
  168. package/types/model_structure/dbState.d.ts +0 -0
  169. package/types/model_structure/element.d.ts +0 -0
  170. package/types/model_structure/endpoint.d.ts +0 -0
  171. package/types/model_structure/enum.d.ts +0 -0
  172. package/types/model_structure/enumValue.d.ts +0 -0
  173. package/types/model_structure/field.d.ts +0 -0
  174. package/types/model_structure/indexColumn.d.ts +0 -0
  175. package/types/model_structure/indexes.d.ts +0 -0
  176. package/types/model_structure/ref.d.ts +0 -0
  177. package/types/model_structure/schema.d.ts +0 -0
  178. package/types/model_structure/stickyNote.d.ts +0 -0
  179. package/types/model_structure/table.d.ts +0 -0
  180. package/types/model_structure/tableGroup.d.ts +0 -0
  181. package/types/model_structure/tablePartial.d.ts +0 -0
  182. package/types/parse/Parser.d.ts +0 -0
  183. package/types/parse/error.d.ts +0 -0
  184. package/types/transform/index.d.ts +7 -0
@@ -1,157 +1,252 @@
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) |
1
+ # PostgreSQL SQL Parser Support
2
+
3
+ > Comprehensive documentation for the PostgreSQL model structure generator based on the ANTLR4 parser.
4
+
5
+ ## Overview
6
+
7
+ This module provides SQL parsing capabilities for PostgreSQL databases, enabling conversion of PostgreSQL DDL statements to DBML format. The parser supports a wide range of PostgreSQL-specific syntax including enumerated types, `SERIAL`/`BIGSERIAL` columns, `GENERATED AS IDENTITY`, and various constraint definitions.
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 PostgreSQL syntax, but the parser fails to generate output |
16
+ | | Syntax not valid in PostgreSQL |
17
+
18
+ ## Key Capabilities
19
+
20
+ - **Data Definition**
21
+ - `CREATE TABLE` with full syntax support
22
+ - Data types: enumerated types, parameterized types (e.g., `VARCHAR(255)`), array types (e.g., `INTEGER[]`)
23
+ - **Constraints**
24
+ - `PRIMARY KEY` (column-level, table-level, multi-column, with explicit name)
25
+ - `FOREIGN KEY` with `ON UPDATE` / `ON DELETE` actions
26
+ - `UNIQUE`, `CHECK`, `DEFAULT`, `NOT NULL`
27
+ - **Auto-increment**
28
+ - `SERIAL` / `BIGSERIAL`
29
+ - `GENERATED AS IDENTITY`
30
+ - **Indexes**
31
+ - `CREATE INDEX` with BTREE, HASH, GIST, BRIN, GIN
32
+ - Function-based indexes (e.g., `LOWER(column)`)
33
+ - **Comments**
34
+ - `COMMENT ON TABLE` / `COMMENT ON COLUMN` statements
35
+ - **Data Manipulation**
36
+ - Basic `INSERT` and multi-row `INSERT`
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 | | |
48
+ | Parameterized types `name(...)` | | e.g., `VARCHAR(255)`, `NUMERIC(10,2)` |
49
+ | Array types `name[...]` | | e.g., `INTEGER[]`, `TEXT[][]` |
50
+ | TEMPORARY tables | | Parsed but no indication of temporary status in output |
51
+ | `CREATE TABLE` AS SELECT | | |
52
+ | Table options (UNLOGGED, partition, etc.) | | Options are ignored |
53
+
54
+ ### Constraints
55
+
56
+ #### `PRIMARY KEY`
57
+
58
+ | Feature | Status | Notes |
59
+ |---------|---------|-------|
60
+ | Column-level `PRIMARY KEY` | | Defined with column: `id INT PRIMARY KEY` |
61
+ | Table-level `PRIMARY KEY` | | Defined separately: `PRIMARY KEY (id)` |
62
+ | Multi-column `PRIMARY KEY` | | Multiple columns: `PRIMARY KEY (a, b)` |
63
+ | Explicitly named (CONSTRAINT name) | | `CONSTRAINT pk_name PRIMARY KEY (id)` |
64
+ | DEFERRABLE / NOT DEFERRABLE || Constraint timing options are ignored |
65
+
66
+ #### `FOREIGN KEY`
67
+
68
+ | Feature | Status | Notes |
69
+ |---------|---------|-------|
70
+ | Column-level `FOREIGN KEY` | | `col INT REFERENCES other(id)` |
71
+ | Table-level `FOREIGN KEY` | | `FOREIGN KEY (col) REFERENCES other(id)` |
72
+ | Multi-column `FOREIGN KEY` | | `FOREIGN KEY (a, b) REFERENCES other(x, y)` |
73
+ | Explicitly named (CONSTRAINT name) | | `CONSTRAINT fk_name FOREIGN KEY ...` |
74
+ | `ON UPDATE` action | | CASCADE, SET NULL, SET DEFAULT, NO ACTION, RESTRICT |
75
+ | `ON DELETE` action | | CASCADE, SET NULL, SET DEFAULT, NO ACTION, RESTRICT |
76
+ | DEFERRABLE / NOT DEFERRABLE | | Constraint timing options are ignored |
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) | | `CONSTRAINT uq_name UNIQUE (col)` |
86
+ | DEFERRABLE / NOT DEFERRABLE | | Constraint timing options are ignored |
87
+ | NULLS NOT DISTINCT | | Treats NULLs as equal (PostgreSQL 15+) - not valid in older versions |
88
+ | `UNIQUE` KEY/`UNIQUE` INDEX syntax || MySQL syntax; use `CREATE INDEX` for indexes |
89
+
90
+ #### `CHECK`
91
+
92
+ | Feature | Status | Notes |
93
+ |---------|---------|-------|
94
+ | Column-level `CHECK` | | `col INT CHECK (col > 0)` |
95
+ | Table-level `CHECK` | | `CHECK (col > 0)` |
96
+ | Explicitly named (CONSTRAINT name) | | Name ignored for column-level checks |
97
+ | NOT VALID / NO INHERIT | | Enforcement options are ignored |
98
+
99
+ #### `DEFAULT`
100
+
101
+ | Feature | Status | Notes |
102
+ |---------|---------|-------|
103
+ | Column-level `DEFAULT` | | `col INT DEFAULT 0` |
104
+ | Table-level `DEFAULT` | | PostgreSQL only supports column-level `DEFAULT` |
105
+ | Function as `DEFAULT` | | `DEFAULT NOW()`, `DEFAULT gen_random_uuid()` |
106
+ | Explicitly named `DEFAULT` | | PostgreSQL doesn't support named `DEFAULT` constraints |
107
+
108
+ #### `NOT NULL` / NULL
109
+
110
+ | Feature | Status | Notes |
111
+ |---------|---------|-------|
112
+ | Column-level `NOT NULL` | | `col INT NOT NULL` |
113
+ | NULL (explicitly nullable) | | `col INT NULL` |
114
+ | Table-level `NOT NULL` | | PostgreSQL only supports column-level `NOT NULL` |
115
+ | DEFERRABLE / NOT DEFERRABLE | | Constraint timing options are ignored |
116
+
117
+ ### Auto-Increment Columns
118
+
119
+ | Feature | Status | Notes |
120
+ |---------|---------|-------|
121
+ | `SERIAL` (pseudo-type) | | `id SERIAL` - auto-incrementing 4-byte integer |
122
+ | `BIGSERIAL` (pseudo-type) | | `id BIGSERIAL` - auto-incrementing 8-byte integer |
123
+ | `GENERATED AS IDENTITY` (column property) | | `id INT GENERATED ALWAYS AS IDENTITY` |
124
+ | START WITH / INCREMENT BY | | Sequence options are ignored |
125
+ | `AUTO_INCREMENT` (column attribute) | | MySQL syntax - not valid in PostgreSQL |
126
+ | `IDENTITY(seed, increment)` (column property) | | SQL Server/Snowflake syntax - not valid in PostgreSQL |
127
+
128
+ ### Inline Indexes (in `CREATE TABLE`)
129
+
130
+ | Feature | Status | Notes |
131
+ |---------|---------|-------|
132
+ | Column-level indexes | | Except for `UNIQUE`/`PRIMARY KEY` constraints |
133
+ | Table-level indexes | | Use `CREATE INDEX` statement |
134
+
135
+ ### Table/Column Comments (in `CREATE TABLE`)
136
+
137
+ | Feature | Status | Notes |
138
+ |---------|---------|-------|
139
+ | Table comments in `CREATE TABLE` | | Use `COMMENT ON` statement |
140
+ | Column comments in `CREATE TABLE` | | Use `COMMENT ON` statement |
141
+
142
+ ---
143
+
144
+ ### `CREATE INDEX`
145
+
146
+ | Feature | Status | Notes |
147
+ |---------|---------|-------|
148
+ | Basic `CREATE INDEX` || `CREATE INDEX idx ON table (col)` |
149
+ | Multi-column index | | `CREATE INDEX idx ON table (a, b)` |
150
+ | Explicitly named index | | Index name is required in PostgreSQL |
151
+ | `UNIQUE` index | ✓ | `CREATE UNIQUE INDEX idx ON table (col)` |
152
+ | BTREE index | | Default index type, B-tree structure |
153
+ | HASH index || Hash-based index for equality comparisons |
154
+ | GIST index | | Generalized Search Tree for complex types |
155
+ | BRIN index | | Block Range Index for large sequential data |
156
+ | GIN index | | Generalized Inverted Index for arrays/JSON |
157
+ | Function-based index | | `CREATE INDEX ON t (LOWER(col))` |
158
+ | Partial index (WHERE clause) | ◐ | `WHERE condition` is ignored |
159
+ | INCLUDE columns | ◐ | Covering index columns are ignored |
160
+ | NULLS FIRST/LAST | ◐ | NULL ordering is ignored |
161
+ | ASC/DESC | ◐ | Sort direction is ignored |
162
+ | COLLATE | ◐ | Collation settings are ignored |
163
+ | Index comments | ◐ | Comments are ignored |
164
+ | CLUSTERED/NONCLUSTERED | — | SQL Server syntax - not valid in PostgreSQL |
165
+ | FULLTEXT index | — | MySQL syntax - use GIN with tsvector |
166
+ | SPATIAL index | — | MySQL syntax - use GIST with geometry |
167
+
168
+ ---
169
+
170
+ ### `INSERT` Statements
171
+
172
+ | Feature | Status | Notes |
173
+ |---------|---------|-------|
174
+ | Basic `INSERT` ... VALUES | ✓ | `INSERT INTO t (col) VALUES (1)` |
175
+ | Multi-row `INSERT` | ✓ | `INSERT INTO t VALUES (1), (2), (3)` |
176
+ | `INSERT` ... SELECT | ✗ | Subquery as data source |
177
+ | WITH clause (CTE) | ✗ | Common Table Expression before `INSERT` |
178
+ | Table alias in `INSERT` | ✗ | `INSERT INTO t AS alias ...` |
179
+ | `INSERT` ... RETURNING | ◐ | Returns inserted rows - clause is ignored |
180
+ | `INSERT` ... ON CONFLICT (UPSERT) | ◐ | Upsert behavior - clause is ignored |
181
+ | `INSERT` OVERWRITE | — | Snowflake/Hive syntax - not valid in PostgreSQL |
182
+ | Multi-table `INSERT` | ✗ | Insert into multiple tables at once |
183
+ | Conditional `INSERT` (WHEN/ALL/FIRST) | ✗ | Oracle syntax for conditional inserts |
184
+
185
+ ---
186
+
187
+ ### `ALTER TABLE`
188
+
189
+ | Feature | Status | Notes |
190
+ |---------|---------|-------|
191
+ | **ADD COLUMN** | | |
192
+ | - All column properties | ✗ | |
193
+ | **DROP COLUMN** | ✗ | |
194
+ | **ALTER COLUMN / MODIFY** | | |
195
+ | - All modifications | ✗ | |
196
+ | **RENAME COLUMN** | ✗ | |
197
+ | **ADD CONSTRAINT** | | |
198
+ | - Named `CHECK` | ✓ | |
199
+ | - Unnamed `CHECK` | ✓ | |
200
+ | - Named `UNIQUE` | ✓ | Name is ignored |
201
+ | - Unnamed `UNIQUE` | ✓ | |
202
+ | - Named `PRIMARY KEY` | ◐ | Name is ignored |
203
+ | - Unnamed `PRIMARY KEY` | ✓ | |
204
+ | - Named `FOREIGN KEY` | ✓ | |
205
+ | - Unnamed `FOREIGN KEY` | ✓ | |
206
+ | - `DEFAULT` | ✗ | Parse failure |
207
+ | - `NOT NULL` / NULL | ✗ | |
208
+ | **DROP CONSTRAINT** | ✗ | |
209
+ | **ALTER CONSTRAINT** | ✗ | |
210
+ | **RENAME TABLE** | ✗ | |
211
+ | **SET SCHEMA** | ✗ | |
212
+
213
+ ---
214
+
215
+ ### Other DDL Statements
216
+
217
+ | Feature | Status | Notes |
218
+ |---------|---------|-------|
219
+ | `DROP TABLE` | ✗ | |
220
+ | `DROP INDEX` | ✗ | |
221
+ | `ALTER INDEX` | ✗ | |
222
+ | `CREATE VIEW` | ✗ | |
223
+
224
+ ---
225
+
226
+ ### Comments (`COMMENT ON`)
227
+
228
+ | Feature | Status | Notes |
229
+ |---------|---------|-------|
230
+ | `COMMENT ON TABLE` | ✓ | |
231
+ | `COMMENT ON COLUMN` | ✓ | |
232
+ | COMMENT ... IS NULL | ✓ | Removes comment |
233
+ | `COMMENT ON INDEX` | ◐ | Ignored |
234
+
235
+ ---
236
+
237
+ ## Known Limitations
238
+
239
+ - **`ALTER TABLE` operations**: Limited support; primarily ADD CONSTRAINT is functional
240
+ - **DDL modification statements**: `DROP TABLE`, `DROP INDEX`, `ALTER INDEX` not supported
241
+ - **`INSERT` ... SELECT**: Subqueries in `INSERT` statements not supported
242
+ - **`CREATE VIEW`**: View definitions are not parsed
243
+ - **Constraint options**: Advanced options like DEFERRABLE, INITIALLY DEFERRED are ignored
244
+ - **Index options**: Partial indexes (WHERE clause), INCLUDE columns, and ordering options are parsed but ignored
245
+
246
+ ## PostgreSQL-Specific Notes
247
+
248
+ 1. **`SERIAL`/`BIGSERIAL`**: These pseudo-types are correctly recognized and converted to auto-increment columns in DBML
249
+ 2. **Enumerated Types**: `CREATE TYPE ... AS ENUM` definitions are supported and referenced enum types in columns are recognized
250
+ 3. **Array Types**: PostgreSQL array syntax (e.g., `INTEGER[]`, `TEXT[][]`) is properly parsed
251
+ 4. **`GENERATED AS IDENTITY`**: The SQL standard identity column syntax is fully supported as an alternative to `SERIAL`
252
+ 5. **Comments**: Use separate `COMMENT ON TABLE/COLUMN` statements rather than inline comments