@dbml/core 3.11.0 → 3.12.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.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/lib/export/DbmlExporter.js +0 -0
- package/lib/export/JsonExporter.js +0 -0
- package/lib/export/ModelExporter.js +0 -0
- package/lib/export/MysqlExporter.js +0 -0
- package/lib/export/OracleExporter.js +0 -0
- package/lib/export/PostgresExporter.js +0 -0
- package/lib/export/README.md +0 -0
- package/lib/export/SqlServerExporter.js +0 -0
- package/lib/export/index.js +0 -0
- package/lib/export/utils.js +0 -0
- package/lib/import/index.js +0 -0
- package/lib/index.js +0 -0
- package/lib/model_structure/config.js +0 -0
- package/lib/model_structure/database.js +39 -10
- package/lib/model_structure/dbState.js +1 -0
- package/lib/model_structure/element.js +0 -0
- package/lib/model_structure/endpoint.js +0 -0
- package/lib/model_structure/enum.js +0 -0
- package/lib/model_structure/enumValue.js +0 -0
- package/lib/model_structure/field.js +0 -0
- package/lib/model_structure/indexColumn.js +0 -0
- package/lib/model_structure/indexes.js +0 -0
- package/lib/model_structure/ref.js +0 -0
- package/lib/model_structure/schema.js +0 -0
- package/lib/model_structure/stickyNote.js +0 -0
- package/lib/model_structure/table.js +0 -0
- package/lib/model_structure/tableGroup.js +0 -0
- package/lib/model_structure/utils.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/AST.js +47 -2
- package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/constants.js +4 -2
- package/lib/parse/ANTLR/ASTGeneration/helpers.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/index.js +21 -5
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +1503 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +157 -4
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +223 -5
- package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +0 -0
- package/lib/parse/ANTLR/README.md +6 -1
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.g4 +1300 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.interp +3643 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.js +1255 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.tokens +2385 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.g4 +6313 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.interp +3034 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.js +3 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.tokens +2385 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParserVisitor.js +5732 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/README.md +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.js +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParserVisitor.js +0 -0
- package/lib/parse/Parser.js +9 -1
- package/lib/parse/buildParser.js +0 -0
- package/lib/parse/databaseGenerator.js +0 -0
- package/lib/parse/dbml/parser.pegjs +0 -0
- package/lib/parse/dbmlParser.js +0 -0
- package/lib/parse/error.js +0 -0
- package/lib/parse/mssql/base_parsers.js +0 -0
- package/lib/parse/mssql/column_definition/actions.js +0 -0
- package/lib/parse/mssql/column_definition/index.js +0 -0
- package/lib/parse/mssql/constraint_definition/actions.js +0 -0
- package/lib/parse/mssql/constraint_definition/index.js +0 -0
- package/lib/parse/mssql/expression.js +0 -0
- package/lib/parse/mssql/fk_definition/actions.js +0 -0
- package/lib/parse/mssql/fk_definition/index.js +0 -0
- package/lib/parse/mssql/index.js +0 -0
- package/lib/parse/mssql/index_definition/actions.js +0 -0
- package/lib/parse/mssql/index_definition/index.js +0 -0
- package/lib/parse/mssql/keyword_parsers.js +0 -0
- package/lib/parse/mssql/keyword_utils.js +0 -0
- package/lib/parse/mssql/statements/actions.js +0 -0
- package/lib/parse/mssql/statements/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/comments/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_index/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_index/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_table/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/index.js +0 -0
- package/lib/parse/mssql/utils.js +0 -0
- package/lib/parse/mssql/whitespaces.js +0 -0
- package/lib/parse/mssqlParser.js +0 -0
- package/lib/parse/mysql/parser.pegjs +0 -0
- package/lib/parse/mysqlParser.js +0 -0
- package/lib/parse/postgresParser.js +0 -0
- package/lib/parse/postgresql/Base_rules.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Commands.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Comment.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_index.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type_range.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +0 -0
- package/lib/parse/postgresql/Expression.pegjs +0 -0
- package/lib/parse/postgresql/InitializerUtils.pegjs +0 -0
- package/lib/parse/postgresql/Keywords.pegjs +0 -0
- package/lib/parse/postgresql/get_parser.js +0 -0
- package/lib/parse/postgresql/parser.pegjs +0 -0
- package/lib/parse/schemarb/parser.pegjs +0 -0
- package/lib/parse/schemarbParser.js +0 -0
- package/lib/utils/version.js +0 -0
- package/package.json +3 -3
- package/types/export/ModelExporter.d.ts +0 -0
- package/types/export/index.d.ts +0 -0
- package/types/import/index.d.ts +1 -1
- package/types/index.d.ts +0 -0
- package/types/model_structure/database.d.ts +34 -1
- package/types/model_structure/dbState.d.ts +0 -0
- package/types/model_structure/element.d.ts +0 -0
- package/types/model_structure/endpoint.d.ts +0 -0
- package/types/model_structure/enum.d.ts +0 -0
- package/types/model_structure/enumValue.d.ts +0 -0
- package/types/model_structure/field.d.ts +0 -0
- package/types/model_structure/indexColumn.d.ts +0 -0
- package/types/model_structure/indexes.d.ts +0 -0
- package/types/model_structure/ref.d.ts +0 -0
- package/types/model_structure/schema.d.ts +0 -0
- package/types/model_structure/stickyNote.d.ts +0 -0
- package/types/model_structure/table.d.ts +0 -0
- package/types/model_structure/tableGroup.d.ts +0 -0
- package/types/parse/Parser.d.ts +3 -2
- package/types/parse/error.d.ts +0 -0
|
@@ -77,7 +77,8 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
77
77
|
enums: [],
|
|
78
78
|
tableGroups: [],
|
|
79
79
|
aliases: [],
|
|
80
|
-
project: {}
|
|
80
|
+
project: {},
|
|
81
|
+
records: []
|
|
81
82
|
};
|
|
82
83
|
return _this;
|
|
83
84
|
}
|
|
@@ -119,6 +120,10 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
119
120
|
value: function visitSqlStatement(ctx) {
|
|
120
121
|
if (ctx.ddlStatement()) {
|
|
121
122
|
ctx.ddlStatement().accept(this);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (ctx.dmlStatement()) {
|
|
126
|
+
ctx.dmlStatement().accept(this);
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
|
|
@@ -216,7 +221,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
216
221
|
// | CREATE TEMPORARY? TABLE ifNotExists? tableName createDefinitions (tableOption (','? tableOption)*)? partitionDefinitions? # columnCreateTable
|
|
217
222
|
}, {
|
|
218
223
|
key: "visitCopyCreateTable",
|
|
219
|
-
value: function visitCopyCreateTable(
|
|
224
|
+
value: function visitCopyCreateTable() {
|
|
220
225
|
// not supported
|
|
221
226
|
}
|
|
222
227
|
}, {
|
|
@@ -629,7 +634,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
629
634
|
// uniqueKeyColumnConstraint: UNIQUE KEY?
|
|
630
635
|
}, {
|
|
631
636
|
key: "visitUniqueKeyColumnConstraint",
|
|
632
|
-
value: function visitUniqueKeyColumnConstraint(
|
|
637
|
+
value: function visitUniqueKeyColumnConstraint() {
|
|
633
638
|
return {
|
|
634
639
|
kind: _constants.COLUMN_CONSTRAINT_KIND.UNIQUE,
|
|
635
640
|
value: true
|
|
@@ -933,7 +938,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
933
938
|
}
|
|
934
939
|
}, {
|
|
935
940
|
key: "visitCheckTableConstraint",
|
|
936
|
-
value: function visitCheckTableConstraint(
|
|
941
|
+
value: function visitCheckTableConstraint() {
|
|
937
942
|
// ignored
|
|
938
943
|
}
|
|
939
944
|
|
|
@@ -1142,6 +1147,154 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
1142
1147
|
});
|
|
1143
1148
|
table.indexes.push(index);
|
|
1144
1149
|
}
|
|
1150
|
+
|
|
1151
|
+
// dmlStatement
|
|
1152
|
+
// : selectStatement | insertStatement | updateStatement | deleteStatement | replaceStatement |
|
|
1153
|
+
// callStatement | loadDataStatement | loadXmlStatement | doStatement | handlerStatement | valuesStatement | withStatement | tableStatement ;
|
|
1154
|
+
}, {
|
|
1155
|
+
key: "visitDmlStatement",
|
|
1156
|
+
value: function visitDmlStatement(ctx) {
|
|
1157
|
+
if (ctx.insertStatement()) {
|
|
1158
|
+
ctx.insertStatement().accept(this);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
// insertStatement
|
|
1163
|
+
// : INSERT priority = (LOW_PRIORITY | DELAYED | HIGH_PRIORITY)? IGNORE? INTO? tableName (
|
|
1164
|
+
// PARTITION '(' partitions = uidList? ')'
|
|
1165
|
+
// )? (
|
|
1166
|
+
// ('(' columns = fullColumnNameList? ')')? insertStatementValue (AS? uid)?
|
|
1167
|
+
// | SET setFirst = updatedElement (',' setElements += updatedElement)*
|
|
1168
|
+
// ) (
|
|
1169
|
+
// ON DUPLICATE KEY UPDATE duplicatedFirst = updatedElement (
|
|
1170
|
+
// ',' duplicatedElements += updatedElement
|
|
1171
|
+
// )*
|
|
1172
|
+
// )?
|
|
1173
|
+
// ;
|
|
1174
|
+
}, {
|
|
1175
|
+
key: "visitInsertStatement",
|
|
1176
|
+
value: function visitInsertStatement(ctx) {
|
|
1177
|
+
var names = ctx.tableName().accept(this);
|
|
1178
|
+
var tableName = (0, _lodash.last)(names);
|
|
1179
|
+
var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
|
|
1180
|
+
|
|
1181
|
+
// insert without specified columns
|
|
1182
|
+
var columns = ctx.fullColumnNameList() ? ctx.fullColumnNameList().accept(this) : [];
|
|
1183
|
+
var values = ctx.insertStatementValue().accept(this);
|
|
1184
|
+
var record = new _AST.TableRecord({
|
|
1185
|
+
schemaName: schemaName,
|
|
1186
|
+
tableName: tableName,
|
|
1187
|
+
columns: columns,
|
|
1188
|
+
values: values
|
|
1189
|
+
});
|
|
1190
|
+
this.data.records.push(record);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// fullColumnNameList
|
|
1194
|
+
// : fullColumnName (',' fullColumnName)*
|
|
1195
|
+
// ;
|
|
1196
|
+
}, {
|
|
1197
|
+
key: "visitFullColumnNameList",
|
|
1198
|
+
value: function visitFullColumnNameList(ctx) {
|
|
1199
|
+
var _this18 = this;
|
|
1200
|
+
// [ [ 'id' ], [ 'name' ], [ 'email' ], [ 'created_at' ] ]
|
|
1201
|
+
var columns = ctx.fullColumnName().map(function (fullColumn) {
|
|
1202
|
+
return fullColumn.accept(_this18);
|
|
1203
|
+
});
|
|
1204
|
+
return (0, _lodash.flattenDepth)(columns, 1);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// insertStatementValue
|
|
1208
|
+
// : selectStatement
|
|
1209
|
+
// | insertFormat = (VALUES | VALUE) '(' expressionsWithDefaults? ')' (
|
|
1210
|
+
// ',' '(' expressionsWithDefaults? ')'
|
|
1211
|
+
// )*
|
|
1212
|
+
// ;
|
|
1213
|
+
}, {
|
|
1214
|
+
key: "visitInsertStatementValue",
|
|
1215
|
+
value: function visitInsertStatementValue(ctx) {
|
|
1216
|
+
var _this19 = this;
|
|
1217
|
+
return ctx.expressionsWithDefaults().map(function (expression) {
|
|
1218
|
+
// [
|
|
1219
|
+
// [ { value: '1', type: 'number' } ],
|
|
1220
|
+
// [ { value: 'Alice', type: 'string' } ],
|
|
1221
|
+
// [ { value: 'alice@host', type: 'string' } ],
|
|
1222
|
+
// [ { value: '2021-01-01', type: 'string' } ],
|
|
1223
|
+
// [ { value: '2021-01-01', type: 'string' } ],
|
|
1224
|
+
// ]
|
|
1225
|
+
var rowValues = expression.accept(_this19);
|
|
1226
|
+
return (0, _lodash.flattenDepth)(rowValues, 1);
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
// expressionsWithDefaults
|
|
1231
|
+
// : expressionOrDefault (',' expressionOrDefault)*
|
|
1232
|
+
// ;
|
|
1233
|
+
}, {
|
|
1234
|
+
key: "visitExpressionsWithDefaults",
|
|
1235
|
+
value: function visitExpressionsWithDefaults(ctx) {
|
|
1236
|
+
var _this20 = this;
|
|
1237
|
+
return ctx.expressionOrDefault().map(function (expressionOrDefault) {
|
|
1238
|
+
var rawValues = expressionOrDefault.accept(_this20);
|
|
1239
|
+
|
|
1240
|
+
// We get the value of the column (constantExpressionAtom or functionCallExpressionAtom) through:
|
|
1241
|
+
// expression->predicate->expressionAtom
|
|
1242
|
+
var FLATTEN_DEPTH = 3;
|
|
1243
|
+
var rawColumnValues = (0, _lodash.flattenDepth)(rawValues, FLATTEN_DEPTH);
|
|
1244
|
+
// [ { value: '["555-1234", "555-5678"]', type: 'string' } ]
|
|
1245
|
+
return rawColumnValues;
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// predicate
|
|
1250
|
+
// : predicate NOT? IN '(' (selectStatement | expressions) ')' # inPredicate
|
|
1251
|
+
// | predicate IS nullNotnull # isNullPredicate
|
|
1252
|
+
// | left = predicate comparisonOperator right = predicate # binaryComparisonPredicate
|
|
1253
|
+
// | predicate comparisonOperator quantifier = (ALL | ANY | SOME) '(' selectStatement ')' # subqueryComparisonPredicate
|
|
1254
|
+
// | predicate NOT? BETWEEN predicate AND predicate # betweenPredicate
|
|
1255
|
+
// | predicate SOUNDS LIKE predicate # soundsLikePredicate
|
|
1256
|
+
// | predicate NOT? LIKE predicate (ESCAPE STRING_LITERAL)? # likePredicate
|
|
1257
|
+
// | predicate NOT? regex = (REGEXP | RLIKE) predicate # regexpPredicate
|
|
1258
|
+
// | predicate MEMBER OF '(' predicate ')' # jsonMemberOfPredicate
|
|
1259
|
+
// | expressionAtom # expressionAtomPredicate
|
|
1260
|
+
// ;
|
|
1261
|
+
|
|
1262
|
+
// expressionAtom
|
|
1263
|
+
// : constant # constantExpressionAtom
|
|
1264
|
+
// | fullColumnName # fullColumnNameExpressionAtom
|
|
1265
|
+
// | functionCall # functionCallExpressionAtom
|
|
1266
|
+
// | expressionAtom COLLATE collationName # collateExpressionAtom
|
|
1267
|
+
// | mysqlVariable # mysqlVariableExpressionAtom
|
|
1268
|
+
// | unaryOperator expressionAtom # unaryExpressionAtom
|
|
1269
|
+
// | BINARY expressionAtom # binaryExpressionAtom
|
|
1270
|
+
// | LOCAL_ID VAR_ASSIGN expressionAtom # variableAssignExpressionAtom
|
|
1271
|
+
// | '(' expression (',' expression)* ')' # nestedExpressionAtom
|
|
1272
|
+
// | ROW '(' expression (',' expression)+ ')' # nestedRowExpressionAtom
|
|
1273
|
+
// | EXISTS '(' selectStatement ')' # existsExpressionAtom
|
|
1274
|
+
// | '(' selectStatement ')' # subqueryExpressionAtom
|
|
1275
|
+
// | INTERVAL expression intervalType # intervalExpressionAtom
|
|
1276
|
+
// | left = expressionAtom bitOperator right = expressionAtom # bitExpressionAtom
|
|
1277
|
+
// | left = expressionAtom multOperator right = expressionAtom # mathExpressionAtom
|
|
1278
|
+
// | left = expressionAtom addOperator right = expressionAtom # mathExpressionAtom
|
|
1279
|
+
// | left = expressionAtom jsonOperator right = expressionAtom # jsonExpressionAtom
|
|
1280
|
+
// ;
|
|
1281
|
+
|
|
1282
|
+
// functionCall
|
|
1283
|
+
// : specificFunction # specificFunctionCall
|
|
1284
|
+
// | aggregateWindowedFunction # aggregateFunctionCall
|
|
1285
|
+
// | nonAggregateWindowedFunction # nonAggregateFunctionCall
|
|
1286
|
+
// | scalarFunctionName '(' functionArgs? ')' # scalarFunctionCall
|
|
1287
|
+
// | fullId '(' functionArgs? ')' # udfFunctionCall
|
|
1288
|
+
// | passwordFunctionClause # passwordFunctionCall
|
|
1289
|
+
// ;
|
|
1290
|
+
}, {
|
|
1291
|
+
key: "visitFunctionCallExpressionAtom",
|
|
1292
|
+
value: function visitFunctionCallExpressionAtom(ctx) {
|
|
1293
|
+
return {
|
|
1294
|
+
value: ctx.getText(),
|
|
1295
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1145
1298
|
}]);
|
|
1146
1299
|
return MySQLASTGen;
|
|
1147
1300
|
}(_MySqlParserVisitor["default"]);
|
|
File without changes
|
|
File without changes
|
|
@@ -69,7 +69,8 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
69
69
|
enums: [],
|
|
70
70
|
tableGroups: [],
|
|
71
71
|
aliases: [],
|
|
72
|
-
project: {}
|
|
72
|
+
project: {},
|
|
73
|
+
records: []
|
|
73
74
|
};
|
|
74
75
|
return _this;
|
|
75
76
|
}
|
|
@@ -129,6 +130,10 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
129
130
|
ctx.definestmt().accept(this);
|
|
130
131
|
return;
|
|
131
132
|
}
|
|
133
|
+
if (ctx.insertstmt()) {
|
|
134
|
+
ctx.insertstmt().accept(this);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
/*
|
|
@@ -238,7 +243,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
238
243
|
})
|
|
239
244
|
// value: {
|
|
240
245
|
// type: 'PrimaryKey',
|
|
241
|
-
// columns:
|
|
246
|
+
// columns:
|
|
242
247
|
// },
|
|
243
248
|
};
|
|
244
249
|
}
|
|
@@ -635,7 +640,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
635
640
|
});
|
|
636
641
|
}
|
|
637
642
|
|
|
638
|
-
// DOT (attr_name | STAR)
|
|
643
|
+
// DOT (attr_name | STAR)
|
|
639
644
|
// | OPEN_BRACKET (a_expr | opt_slice_bound COLON opt_slice_bound) CLOSE_BRACKET
|
|
640
645
|
}, {
|
|
641
646
|
key: "visitIndirection_el",
|
|
@@ -830,7 +835,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
830
835
|
}
|
|
831
836
|
}
|
|
832
837
|
|
|
833
|
-
// name |
|
|
838
|
+
// name |
|
|
834
839
|
}, {
|
|
835
840
|
key: "visitOpt_index_name",
|
|
836
841
|
value: function visitOpt_index_name(ctx) {
|
|
@@ -845,7 +850,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
845
850
|
return ctx.colid().accept(this);
|
|
846
851
|
}
|
|
847
852
|
|
|
848
|
-
// USING name |
|
|
853
|
+
// USING name |
|
|
849
854
|
}, {
|
|
850
855
|
key: "visitAccess_method_clause",
|
|
851
856
|
value: function visitAccess_method_clause(ctx) {
|
|
@@ -1161,6 +1166,219 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
1161
1166
|
return s.accept(_this11);
|
|
1162
1167
|
});
|
|
1163
1168
|
}
|
|
1169
|
+
|
|
1170
|
+
// insertstmt
|
|
1171
|
+
// : opt_with_clause INSERT INTO insert_target insert_rest opt_on_conflict returning_clause
|
|
1172
|
+
// ;
|
|
1173
|
+
}, {
|
|
1174
|
+
key: "visitInsertstmt",
|
|
1175
|
+
value: function visitInsertstmt(ctx) {
|
|
1176
|
+
var names = ctx.insert_target().accept(this);
|
|
1177
|
+
var tableName = (0, _lodash.last)(names);
|
|
1178
|
+
var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
|
|
1179
|
+
var _ctx$insert_rest$acce = ctx.insert_rest().accept(this),
|
|
1180
|
+
columns = _ctx$insert_rest$acce.columns,
|
|
1181
|
+
values = _ctx$insert_rest$acce.values;
|
|
1182
|
+
var record = new _AST.TableRecord({
|
|
1183
|
+
schemaName: schemaName,
|
|
1184
|
+
tableName: tableName,
|
|
1185
|
+
columns: columns,
|
|
1186
|
+
values: values
|
|
1187
|
+
});
|
|
1188
|
+
this.data.records.push(record);
|
|
1189
|
+
}
|
|
1190
|
+
}, {
|
|
1191
|
+
key: "visitInsert_target",
|
|
1192
|
+
value: function visitInsert_target(ctx) {
|
|
1193
|
+
return ctx.qualified_name().accept(this);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// insert_rest
|
|
1197
|
+
// : selectstmt
|
|
1198
|
+
// | OVERRIDING override_kind VALUE_P selectstmt
|
|
1199
|
+
// | OPEN_PAREN insert_column_list CLOSE_PAREN (OVERRIDING override_kind VALUE_P)? selectstmt
|
|
1200
|
+
// | DEFAULT VALUES
|
|
1201
|
+
// ;
|
|
1202
|
+
}, {
|
|
1203
|
+
key: "visitInsert_rest",
|
|
1204
|
+
value: function visitInsert_rest(ctx) {
|
|
1205
|
+
var columns = ctx.insert_column_list() ? ctx.insert_column_list().accept(this) : [];
|
|
1206
|
+
var rowsValue = ctx.selectstmt().accept(this) || [];
|
|
1207
|
+
// each sub array represents a set of value of a row
|
|
1208
|
+
// [
|
|
1209
|
+
// [
|
|
1210
|
+
// { value: '1', type: 'number' },
|
|
1211
|
+
// undefined,
|
|
1212
|
+
// {
|
|
1213
|
+
// value: '{"theme": "dark", "notifications": true}',
|
|
1214
|
+
// type: 'string',
|
|
1215
|
+
// type_name: 'JSONB',
|
|
1216
|
+
// schemaName: null
|
|
1217
|
+
// },
|
|
1218
|
+
// undefined,
|
|
1219
|
+
// ]
|
|
1220
|
+
// ]
|
|
1221
|
+
|
|
1222
|
+
var sanitizeRowValue = function sanitizeRowValue(rowValue) {
|
|
1223
|
+
return rowValue.filter(function (row) {
|
|
1224
|
+
return row;
|
|
1225
|
+
}).map(function (_ref) {
|
|
1226
|
+
var value = _ref.value,
|
|
1227
|
+
type = _ref.type;
|
|
1228
|
+
return {
|
|
1229
|
+
value: value,
|
|
1230
|
+
type: type
|
|
1231
|
+
};
|
|
1232
|
+
});
|
|
1233
|
+
};
|
|
1234
|
+
var sanitizedRowsValue = rowsValue.filter(function (rowValue) {
|
|
1235
|
+
return Array.isArray(rowValue);
|
|
1236
|
+
}).map(sanitizeRowValue);
|
|
1237
|
+
return {
|
|
1238
|
+
columns: columns,
|
|
1239
|
+
values: sanitizedRowsValue
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// insert_column_list
|
|
1244
|
+
// : insert_column_item (COMMA insert_column_item)*
|
|
1245
|
+
// ;
|
|
1246
|
+
}, {
|
|
1247
|
+
key: "visitInsert_column_list",
|
|
1248
|
+
value: function visitInsert_column_list(ctx) {
|
|
1249
|
+
var _this12 = this;
|
|
1250
|
+
return ctx.insert_column_item().map(function (colItem) {
|
|
1251
|
+
return colItem.accept(_this12);
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// insert_column_item
|
|
1256
|
+
// : colid opt_indirection
|
|
1257
|
+
// ;
|
|
1258
|
+
}, {
|
|
1259
|
+
key: "visitInsert_column_item",
|
|
1260
|
+
value: function visitInsert_column_item(ctx) {
|
|
1261
|
+
return ctx.colid().accept(this);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// selectstmt
|
|
1265
|
+
// : select_no_parens
|
|
1266
|
+
// | select_with_parens
|
|
1267
|
+
// ;
|
|
1268
|
+
}, {
|
|
1269
|
+
key: "visitSelectstmt",
|
|
1270
|
+
value: function visitSelectstmt(ctx) {
|
|
1271
|
+
if (!ctx.select_no_parens()) {
|
|
1272
|
+
return null;
|
|
1273
|
+
}
|
|
1274
|
+
return ctx.select_no_parens().accept(this);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// select_no_parens
|
|
1278
|
+
// : select_clause opt_sort_clause (for_locking_clause opt_select_limit | select_limit opt_for_locking_clause)?
|
|
1279
|
+
// | with_clause select_clause opt_sort_clause (for_locking_clause opt_select_limit | select_limit opt_for_locking_clause)?
|
|
1280
|
+
// ;
|
|
1281
|
+
}, {
|
|
1282
|
+
key: "visitSelect_no_parens",
|
|
1283
|
+
value: function visitSelect_no_parens(ctx) {
|
|
1284
|
+
return ctx.select_clause().accept(this);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
// select_clause
|
|
1288
|
+
// : simple_select
|
|
1289
|
+
// | select_with_parens
|
|
1290
|
+
// ;
|
|
1291
|
+
}, {
|
|
1292
|
+
key: "visitSelect_clause",
|
|
1293
|
+
value: function visitSelect_clause(ctx) {
|
|
1294
|
+
return ctx.simple_select().accept(this);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// simple_select
|
|
1298
|
+
// : ( SELECT (opt_all_clause into_clause opt_target_list | distinct_clause target_list)
|
|
1299
|
+
// into_clause
|
|
1300
|
+
// from_clause
|
|
1301
|
+
// where_clause
|
|
1302
|
+
// group_clause
|
|
1303
|
+
// having_clause
|
|
1304
|
+
// window_clause
|
|
1305
|
+
// | values_clause
|
|
1306
|
+
// | TABLE relation_expr
|
|
1307
|
+
// | select_with_parens set_operator_with_all_or_distinct (simple_select | select_with_parens)
|
|
1308
|
+
// )
|
|
1309
|
+
// (set_operator_with_all_or_distinct (simple_select | select_with_parens))*
|
|
1310
|
+
// ;
|
|
1311
|
+
}, {
|
|
1312
|
+
key: "visitSimple_select",
|
|
1313
|
+
value: function visitSimple_select(ctx) {
|
|
1314
|
+
if (!ctx.values_clause()) {
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
return ctx.values_clause().accept(this);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// values_clause
|
|
1321
|
+
// : VALUES OPEN_PAREN expr_list CLOSE_PAREN (COMMA OPEN_PAREN expr_list CLOSE_PAREN)*
|
|
1322
|
+
// ;
|
|
1323
|
+
}, {
|
|
1324
|
+
key: "visitValues_clause",
|
|
1325
|
+
value: function visitValues_clause(ctx) {
|
|
1326
|
+
var _this13 = this;
|
|
1327
|
+
return ctx.expr_list().map(function (expr) {
|
|
1328
|
+
var rawValues = expr.accept(_this13);
|
|
1329
|
+
|
|
1330
|
+
// We get the value of the c_expr through:
|
|
1331
|
+
// a_expr->a_expr_qual->a_expr_lessless->a_expr_or->a_expr_and->
|
|
1332
|
+
// a_expr_between->a_expr_in->a_expr_unary_not->a_expr_isnull->a_expr_is_not->
|
|
1333
|
+
// a_expr_compare->a_expr_like->a_expr_qual_op->a_expr_unary_qualop->a_expr_add->
|
|
1334
|
+
// a_expr_mul->a_expr_caret->a_expr_unary_sign->a_expr_at_time_zone->a_expr_collate->
|
|
1335
|
+
// a_expr_typecast
|
|
1336
|
+
var FLATTEN_DEPTH = 21;
|
|
1337
|
+
var rawRowValues = (0, _lodash.flattenDepth)(rawValues, FLATTEN_DEPTH);
|
|
1338
|
+
|
|
1339
|
+
// [
|
|
1340
|
+
// { value: '1', type: 'number' },
|
|
1341
|
+
// undefined,
|
|
1342
|
+
// {
|
|
1343
|
+
// value: '{"theme": "dark", "notifications": true}',
|
|
1344
|
+
// type: 'string',
|
|
1345
|
+
// type_name: 'JSONB',
|
|
1346
|
+
// schemaName: null
|
|
1347
|
+
// },
|
|
1348
|
+
// undefined,
|
|
1349
|
+
// ]
|
|
1350
|
+
return rawRowValues;
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// a_expr_collate
|
|
1355
|
+
// : a_expr_typecast (COLLATE any_name)?
|
|
1356
|
+
// ;
|
|
1357
|
+
}, {
|
|
1358
|
+
key: "visitA_expr_collate",
|
|
1359
|
+
value: function visitA_expr_collate(ctx) {
|
|
1360
|
+
var expressionValueSet = ctx.a_expr_typecast().accept(this);
|
|
1361
|
+
|
|
1362
|
+
// Possible values
|
|
1363
|
+
// 1: [ { value: 'inactive', type: 'string' } ]
|
|
1364
|
+
// 2: [
|
|
1365
|
+
// { value: '2021-01-05 18:45:00+00', type: 'string' },
|
|
1366
|
+
// undefined,
|
|
1367
|
+
// { type_name: 'TIMESTAMPTZ', schemaName: null }
|
|
1368
|
+
// ]
|
|
1369
|
+
// eslint-disable-next-line no-unused-vars
|
|
1370
|
+
var _expressionValueSet = _slicedToArray(expressionValueSet, 3),
|
|
1371
|
+
rawValue = _expressionValueSet[0],
|
|
1372
|
+
_ = _expressionValueSet[1],
|
|
1373
|
+
_expressionValueSet$ = _expressionValueSet[2],
|
|
1374
|
+
rawType = _expressionValueSet$ === void 0 ? {} : _expressionValueSet$;
|
|
1375
|
+
var value = rawValue.value,
|
|
1376
|
+
type = rawValue.type;
|
|
1377
|
+
return _objectSpread({
|
|
1378
|
+
value: value,
|
|
1379
|
+
type: type
|
|
1380
|
+
}, rawType);
|
|
1381
|
+
}
|
|
1164
1382
|
}]);
|
|
1165
1383
|
return PostgresASTGen;
|
|
1166
1384
|
}(_PostgreSQLParserVisitor["default"]);
|
|
File without changes
|
|
@@ -14,7 +14,12 @@
|
|
|
14
14
|
- https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md
|
|
15
15
|
## Setup a new parser
|
|
16
16
|
1. Create a new folder inside the `packages/dbml-core/src/parse/ANTLR/parsers` folder (e.g. `postgresql`)
|
|
17
|
-
2.
|
|
17
|
+
2. Get the grammar:
|
|
18
|
+
|
|
19
|
+
- Go to https://github.com/antlr/grammars-v4/tree/master/sql and clone the `<lang>Lexer.G4` and `<lang>Parser.G4` to the newly created folder.
|
|
20
|
+
|
|
21
|
+
- **Remember to add the original link to `<lang>Lexer.G4` and `<lang>Parser.G4`**
|
|
22
|
+
|
|
18
23
|
3. Go to the folder:
|
|
19
24
|
```
|
|
20
25
|
cd packages/dbml-core/src/parse/ANTLR/parsers/postgresql
|