@dbml/core 3.10.2 → 3.11.0-alpha-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/lib/model_structure/database.js +6 -2
- package/lib/model_structure/utils.js +6 -0
- package/lib/parse/ANTLR/ASTGeneration/index.js +21 -5
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +393 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +165 -4
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +236 -5
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.g4 +1294 -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 +6307 -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/Parser.js +10 -0
- package/package.json +3 -3
- package/types/model_structure/database.d.ts +16 -1
- package/types/parse/Parser.d.ts +2 -1
|
@@ -9,6 +9,7 @@ var _lodash = require("lodash");
|
|
|
9
9
|
var _MySqlParserVisitor = _interopRequireDefault(require("../../parsers/mysql/MySqlParserVisitor"));
|
|
10
10
|
var _AST = require("../AST");
|
|
11
11
|
var _constants = require("../constants");
|
|
12
|
+
var _utils = require("../../../../model_structure/utils");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -77,7 +78,8 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
77
78
|
enums: [],
|
|
78
79
|
tableGroups: [],
|
|
79
80
|
aliases: [],
|
|
80
|
-
project: {}
|
|
81
|
+
project: {},
|
|
82
|
+
records: {}
|
|
81
83
|
};
|
|
82
84
|
return _this;
|
|
83
85
|
}
|
|
@@ -119,6 +121,10 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
119
121
|
value: function visitSqlStatement(ctx) {
|
|
120
122
|
if (ctx.ddlStatement()) {
|
|
121
123
|
ctx.ddlStatement().accept(this);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (ctx.dmlStatement()) {
|
|
127
|
+
ctx.dmlStatement().accept(this);
|
|
122
128
|
}
|
|
123
129
|
}
|
|
124
130
|
|
|
@@ -216,7 +222,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
216
222
|
// | CREATE TEMPORARY? TABLE ifNotExists? tableName createDefinitions (tableOption (','? tableOption)*)? partitionDefinitions? # columnCreateTable
|
|
217
223
|
}, {
|
|
218
224
|
key: "visitCopyCreateTable",
|
|
219
|
-
value: function visitCopyCreateTable(
|
|
225
|
+
value: function visitCopyCreateTable() {
|
|
220
226
|
// not supported
|
|
221
227
|
}
|
|
222
228
|
}, {
|
|
@@ -629,7 +635,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
629
635
|
// uniqueKeyColumnConstraint: UNIQUE KEY?
|
|
630
636
|
}, {
|
|
631
637
|
key: "visitUniqueKeyColumnConstraint",
|
|
632
|
-
value: function visitUniqueKeyColumnConstraint(
|
|
638
|
+
value: function visitUniqueKeyColumnConstraint() {
|
|
633
639
|
return {
|
|
634
640
|
kind: _constants.COLUMN_CONSTRAINT_KIND.UNIQUE,
|
|
635
641
|
value: true
|
|
@@ -933,7 +939,7 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
933
939
|
}
|
|
934
940
|
}, {
|
|
935
941
|
key: "visitCheckTableConstraint",
|
|
936
|
-
value: function visitCheckTableConstraint(
|
|
942
|
+
value: function visitCheckTableConstraint() {
|
|
937
943
|
// ignored
|
|
938
944
|
}
|
|
939
945
|
|
|
@@ -1142,6 +1148,161 @@ var MySQLASTGen = /*#__PURE__*/function (_MySQLParserVisitor) {
|
|
|
1142
1148
|
});
|
|
1143
1149
|
table.indexes.push(index);
|
|
1144
1150
|
}
|
|
1151
|
+
|
|
1152
|
+
// dmlStatement
|
|
1153
|
+
// : selectStatement | insertStatement | updateStatement | deleteStatement | replaceStatement |
|
|
1154
|
+
// callStatement | loadDataStatement | loadXmlStatement | doStatement | handlerStatement | valuesStatement | withStatement | tableStatement ;
|
|
1155
|
+
}, {
|
|
1156
|
+
key: "visitDmlStatement",
|
|
1157
|
+
value: function visitDmlStatement(ctx) {
|
|
1158
|
+
if (ctx.insertStatement()) {
|
|
1159
|
+
ctx.insertStatement().accept(this);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// insertStatement
|
|
1164
|
+
// : INSERT priority = (LOW_PRIORITY | DELAYED | HIGH_PRIORITY)? IGNORE? INTO? tableName (
|
|
1165
|
+
// PARTITION '(' partitions = uidList? ')'
|
|
1166
|
+
// )? (
|
|
1167
|
+
// ('(' columns = fullColumnNameList? ')')? insertStatementValue (AS? uid)?
|
|
1168
|
+
// | SET setFirst = updatedElement (',' setElements += updatedElement)*
|
|
1169
|
+
// ) (
|
|
1170
|
+
// ON DUPLICATE KEY UPDATE duplicatedFirst = updatedElement (
|
|
1171
|
+
// ',' duplicatedElements += updatedElement
|
|
1172
|
+
// )*
|
|
1173
|
+
// )?
|
|
1174
|
+
// ;
|
|
1175
|
+
}, {
|
|
1176
|
+
key: "visitInsertStatement",
|
|
1177
|
+
value: function visitInsertStatement(ctx) {
|
|
1178
|
+
var _this$data$records$fu;
|
|
1179
|
+
var names = ctx.tableName().accept(this);
|
|
1180
|
+
var tableName = (0, _lodash.last)(names);
|
|
1181
|
+
var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
|
|
1182
|
+
var fullTableName = (0, _utils.getFullTableName)(schemaName, tableName);
|
|
1183
|
+
|
|
1184
|
+
// insert without specified columns
|
|
1185
|
+
var columns = ctx.fullColumnNameList() ? ctx.fullColumnNameList().accept(this) : [];
|
|
1186
|
+
var values = ctx.insertStatementValue().accept(this);
|
|
1187
|
+
if (columns.length === 0 || values.length === 0) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
if (!this.data.records[fullTableName]) {
|
|
1191
|
+
this.data.records[fullTableName] = {
|
|
1192
|
+
schemaName: schemaName,
|
|
1193
|
+
tableName: tableName,
|
|
1194
|
+
columns: columns,
|
|
1195
|
+
values: []
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
(_this$data$records$fu = this.data.records[fullTableName].values).push.apply(_this$data$records$fu, _toConsumableArray(values));
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// fullColumnNameList
|
|
1202
|
+
// : fullColumnName (',' fullColumnName)*
|
|
1203
|
+
// ;
|
|
1204
|
+
}, {
|
|
1205
|
+
key: "visitFullColumnNameList",
|
|
1206
|
+
value: function visitFullColumnNameList(ctx) {
|
|
1207
|
+
var _this18 = this;
|
|
1208
|
+
// [ [ 'id' ], [ 'name' ], [ 'email' ], [ 'created_at' ] ]
|
|
1209
|
+
var columns = ctx.fullColumnName().map(function (fullColumn) {
|
|
1210
|
+
return fullColumn.accept(_this18);
|
|
1211
|
+
});
|
|
1212
|
+
return (0, _lodash.flattenDepth)(columns, 1);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// insertStatementValue
|
|
1216
|
+
// : selectStatement
|
|
1217
|
+
// | insertFormat = (VALUES | VALUE) '(' expressionsWithDefaults? ')' (
|
|
1218
|
+
// ',' '(' expressionsWithDefaults? ')'
|
|
1219
|
+
// )*
|
|
1220
|
+
// ;
|
|
1221
|
+
}, {
|
|
1222
|
+
key: "visitInsertStatementValue",
|
|
1223
|
+
value: function visitInsertStatementValue(ctx) {
|
|
1224
|
+
var _this19 = this;
|
|
1225
|
+
return ctx.expressionsWithDefaults().map(function (expression) {
|
|
1226
|
+
// [
|
|
1227
|
+
// [ { value: '1', type: 'number' } ],
|
|
1228
|
+
// [ { value: 'Alice', type: 'string' } ],
|
|
1229
|
+
// [ { value: 'alice@host', type: 'string' } ],
|
|
1230
|
+
// [ { value: '2021-01-01', type: 'string' } ],
|
|
1231
|
+
// [ { value: '2021-01-01', type: 'string' } ],
|
|
1232
|
+
// ]
|
|
1233
|
+
var rowValues = expression.accept(_this19);
|
|
1234
|
+
return (0, _lodash.flattenDepth)(rowValues, 1);
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// expressionsWithDefaults
|
|
1239
|
+
// : expressionOrDefault (',' expressionOrDefault)*
|
|
1240
|
+
// ;
|
|
1241
|
+
}, {
|
|
1242
|
+
key: "visitExpressionsWithDefaults",
|
|
1243
|
+
value: function visitExpressionsWithDefaults(ctx) {
|
|
1244
|
+
var _this20 = this;
|
|
1245
|
+
return ctx.expressionOrDefault().map(function (expressionOrDefault) {
|
|
1246
|
+
var rawValues = expressionOrDefault.accept(_this20);
|
|
1247
|
+
|
|
1248
|
+
// We get the value of the column (constantExpressionAtom or functionCallExpressionAtom) through:
|
|
1249
|
+
// expression->predicate->expressionAtom
|
|
1250
|
+
var FLATTEN_DEPTH = 3;
|
|
1251
|
+
var rawColumnValues = (0, _lodash.flattenDepth)(rawValues, FLATTEN_DEPTH);
|
|
1252
|
+
// [ { value: '["555-1234", "555-5678"]', type: 'string' } ]
|
|
1253
|
+
return rawColumnValues;
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// predicate
|
|
1258
|
+
// : predicate NOT? IN '(' (selectStatement | expressions) ')' # inPredicate
|
|
1259
|
+
// | predicate IS nullNotnull # isNullPredicate
|
|
1260
|
+
// | left = predicate comparisonOperator right = predicate # binaryComparisonPredicate
|
|
1261
|
+
// | predicate comparisonOperator quantifier = (ALL | ANY | SOME) '(' selectStatement ')' # subqueryComparisonPredicate
|
|
1262
|
+
// | predicate NOT? BETWEEN predicate AND predicate # betweenPredicate
|
|
1263
|
+
// | predicate SOUNDS LIKE predicate # soundsLikePredicate
|
|
1264
|
+
// | predicate NOT? LIKE predicate (ESCAPE STRING_LITERAL)? # likePredicate
|
|
1265
|
+
// | predicate NOT? regex = (REGEXP | RLIKE) predicate # regexpPredicate
|
|
1266
|
+
// | predicate MEMBER OF '(' predicate ')' # jsonMemberOfPredicate
|
|
1267
|
+
// | expressionAtom # expressionAtomPredicate
|
|
1268
|
+
// ;
|
|
1269
|
+
|
|
1270
|
+
// expressionAtom
|
|
1271
|
+
// : constant # constantExpressionAtom
|
|
1272
|
+
// | fullColumnName # fullColumnNameExpressionAtom
|
|
1273
|
+
// | functionCall # functionCallExpressionAtom
|
|
1274
|
+
// | expressionAtom COLLATE collationName # collateExpressionAtom
|
|
1275
|
+
// | mysqlVariable # mysqlVariableExpressionAtom
|
|
1276
|
+
// | unaryOperator expressionAtom # unaryExpressionAtom
|
|
1277
|
+
// | BINARY expressionAtom # binaryExpressionAtom
|
|
1278
|
+
// | LOCAL_ID VAR_ASSIGN expressionAtom # variableAssignExpressionAtom
|
|
1279
|
+
// | '(' expression (',' expression)* ')' # nestedExpressionAtom
|
|
1280
|
+
// | ROW '(' expression (',' expression)+ ')' # nestedRowExpressionAtom
|
|
1281
|
+
// | EXISTS '(' selectStatement ')' # existsExpressionAtom
|
|
1282
|
+
// | '(' selectStatement ')' # subqueryExpressionAtom
|
|
1283
|
+
// | INTERVAL expression intervalType # intervalExpressionAtom
|
|
1284
|
+
// | left = expressionAtom bitOperator right = expressionAtom # bitExpressionAtom
|
|
1285
|
+
// | left = expressionAtom multOperator right = expressionAtom # mathExpressionAtom
|
|
1286
|
+
// | left = expressionAtom addOperator right = expressionAtom # mathExpressionAtom
|
|
1287
|
+
// | left = expressionAtom jsonOperator right = expressionAtom # jsonExpressionAtom
|
|
1288
|
+
// ;
|
|
1289
|
+
|
|
1290
|
+
// functionCall
|
|
1291
|
+
// : specificFunction # specificFunctionCall
|
|
1292
|
+
// | aggregateWindowedFunction # aggregateFunctionCall
|
|
1293
|
+
// | nonAggregateWindowedFunction # nonAggregateFunctionCall
|
|
1294
|
+
// | scalarFunctionName '(' functionArgs? ')' # scalarFunctionCall
|
|
1295
|
+
// | fullId '(' functionArgs? ')' # udfFunctionCall
|
|
1296
|
+
// | passwordFunctionClause # passwordFunctionCall
|
|
1297
|
+
// ;
|
|
1298
|
+
}, {
|
|
1299
|
+
key: "visitFunctionCallExpressionAtom",
|
|
1300
|
+
value: function visitFunctionCallExpressionAtom(ctx) {
|
|
1301
|
+
return {
|
|
1302
|
+
value: ctx.getText(),
|
|
1303
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1145
1306
|
}]);
|
|
1146
1307
|
return MySQLASTGen;
|
|
1147
1308
|
}(_MySqlParserVisitor["default"]);
|
|
@@ -9,6 +9,7 @@ var _lodash = require("lodash");
|
|
|
9
9
|
var _PostgreSQLParserVisitor = _interopRequireDefault(require("../../parsers/postgresql/PostgreSQLParserVisitor"));
|
|
10
10
|
var _AST = require("../AST");
|
|
11
11
|
var _constants = require("../constants");
|
|
12
|
+
var _utils = require("../../../../model_structure/utils");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -69,7 +70,8 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
69
70
|
enums: [],
|
|
70
71
|
tableGroups: [],
|
|
71
72
|
aliases: [],
|
|
72
|
-
project: {}
|
|
73
|
+
project: {},
|
|
74
|
+
records: {}
|
|
73
75
|
};
|
|
74
76
|
return _this;
|
|
75
77
|
}
|
|
@@ -129,6 +131,10 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
129
131
|
ctx.definestmt().accept(this);
|
|
130
132
|
return;
|
|
131
133
|
}
|
|
134
|
+
if (ctx.insertstmt()) {
|
|
135
|
+
ctx.insertstmt().accept(this);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
/*
|
|
@@ -238,7 +244,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
238
244
|
})
|
|
239
245
|
// value: {
|
|
240
246
|
// type: 'PrimaryKey',
|
|
241
|
-
// columns:
|
|
247
|
+
// columns:
|
|
242
248
|
// },
|
|
243
249
|
};
|
|
244
250
|
}
|
|
@@ -635,7 +641,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
635
641
|
});
|
|
636
642
|
}
|
|
637
643
|
|
|
638
|
-
// DOT (attr_name | STAR)
|
|
644
|
+
// DOT (attr_name | STAR)
|
|
639
645
|
// | OPEN_BRACKET (a_expr | opt_slice_bound COLON opt_slice_bound) CLOSE_BRACKET
|
|
640
646
|
}, {
|
|
641
647
|
key: "visitIndirection_el",
|
|
@@ -830,7 +836,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
830
836
|
}
|
|
831
837
|
}
|
|
832
838
|
|
|
833
|
-
// name |
|
|
839
|
+
// name |
|
|
834
840
|
}, {
|
|
835
841
|
key: "visitOpt_index_name",
|
|
836
842
|
value: function visitOpt_index_name(ctx) {
|
|
@@ -845,7 +851,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
845
851
|
return ctx.colid().accept(this);
|
|
846
852
|
}
|
|
847
853
|
|
|
848
|
-
// USING name |
|
|
854
|
+
// USING name |
|
|
849
855
|
}, {
|
|
850
856
|
key: "visitAccess_method_clause",
|
|
851
857
|
value: function visitAccess_method_clause(ctx) {
|
|
@@ -1161,6 +1167,231 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
|
|
|
1161
1167
|
return s.accept(_this11);
|
|
1162
1168
|
});
|
|
1163
1169
|
}
|
|
1170
|
+
|
|
1171
|
+
// insertstmt
|
|
1172
|
+
// : opt_with_clause INSERT INTO insert_target insert_rest opt_on_conflict returning_clause
|
|
1173
|
+
// ;
|
|
1174
|
+
}, {
|
|
1175
|
+
key: "visitInsertstmt",
|
|
1176
|
+
value: function visitInsertstmt(ctx) {
|
|
1177
|
+
var _this$data$records$fu;
|
|
1178
|
+
var names = ctx.insert_target().accept(this);
|
|
1179
|
+
var tableName = (0, _lodash.last)(names);
|
|
1180
|
+
var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
|
|
1181
|
+
var fullTableName = (0, _utils.getFullTableName)(schemaName, tableName);
|
|
1182
|
+
var _ctx$insert_rest$acce = ctx.insert_rest().accept(this),
|
|
1183
|
+
columns = _ctx$insert_rest$acce.columns,
|
|
1184
|
+
values = _ctx$insert_rest$acce.values;
|
|
1185
|
+
|
|
1186
|
+
// handle insert into all columns
|
|
1187
|
+
if (columns.length === 0 || values.length === 0) {
|
|
1188
|
+
// temporarily ignore
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
if (!this.data.records[fullTableName]) {
|
|
1192
|
+
this.data.records[fullTableName] = {
|
|
1193
|
+
schemaName: schemaName,
|
|
1194
|
+
tableName: tableName,
|
|
1195
|
+
columns: columns,
|
|
1196
|
+
values: []
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// TODO: should handle case the number of columns is not equal
|
|
1201
|
+
(_this$data$records$fu = this.data.records[fullTableName].values).push.apply(_this$data$records$fu, _toConsumableArray(values));
|
|
1202
|
+
}
|
|
1203
|
+
}, {
|
|
1204
|
+
key: "visitInsert_target",
|
|
1205
|
+
value: function visitInsert_target(ctx) {
|
|
1206
|
+
return ctx.qualified_name().accept(this);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// insert_rest
|
|
1210
|
+
// : selectstmt
|
|
1211
|
+
// | OVERRIDING override_kind VALUE_P selectstmt
|
|
1212
|
+
// | OPEN_PAREN insert_column_list CLOSE_PAREN (OVERRIDING override_kind VALUE_P)? selectstmt
|
|
1213
|
+
// | DEFAULT VALUES
|
|
1214
|
+
// ;
|
|
1215
|
+
}, {
|
|
1216
|
+
key: "visitInsert_rest",
|
|
1217
|
+
value: function visitInsert_rest(ctx) {
|
|
1218
|
+
var columns = ctx.insert_column_list() ? ctx.insert_column_list().accept(this) : [];
|
|
1219
|
+
var rowsValue = ctx.selectstmt().accept(this) || [];
|
|
1220
|
+
// each sub array represents a set of value of a row
|
|
1221
|
+
// [
|
|
1222
|
+
// [
|
|
1223
|
+
// { value: '1', type: 'number' },
|
|
1224
|
+
// undefined,
|
|
1225
|
+
// {
|
|
1226
|
+
// value: '{"theme": "dark", "notifications": true}',
|
|
1227
|
+
// type: 'string',
|
|
1228
|
+
// type_name: 'JSONB',
|
|
1229
|
+
// schemaName: null
|
|
1230
|
+
// },
|
|
1231
|
+
// undefined,
|
|
1232
|
+
// ]
|
|
1233
|
+
// ]
|
|
1234
|
+
|
|
1235
|
+
var sanitizeRowValue = function sanitizeRowValue(rowValue) {
|
|
1236
|
+
return rowValue.filter(function (row) {
|
|
1237
|
+
return row;
|
|
1238
|
+
}).map(function (_ref) {
|
|
1239
|
+
var value = _ref.value,
|
|
1240
|
+
type = _ref.type;
|
|
1241
|
+
return {
|
|
1242
|
+
value: value,
|
|
1243
|
+
type: type
|
|
1244
|
+
};
|
|
1245
|
+
});
|
|
1246
|
+
};
|
|
1247
|
+
var sanitizedRowsValue = rowsValue.filter(function (rowValue) {
|
|
1248
|
+
return Array.isArray(rowValue);
|
|
1249
|
+
}).map(sanitizeRowValue);
|
|
1250
|
+
return {
|
|
1251
|
+
columns: columns,
|
|
1252
|
+
values: sanitizedRowsValue
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// insert_column_list
|
|
1257
|
+
// : insert_column_item (COMMA insert_column_item)*
|
|
1258
|
+
// ;
|
|
1259
|
+
}, {
|
|
1260
|
+
key: "visitInsert_column_list",
|
|
1261
|
+
value: function visitInsert_column_list(ctx) {
|
|
1262
|
+
var _this12 = this;
|
|
1263
|
+
return ctx.insert_column_item().map(function (colItem) {
|
|
1264
|
+
return colItem.accept(_this12);
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// insert_column_item
|
|
1269
|
+
// : colid opt_indirection
|
|
1270
|
+
// ;
|
|
1271
|
+
}, {
|
|
1272
|
+
key: "visitInsert_column_item",
|
|
1273
|
+
value: function visitInsert_column_item(ctx) {
|
|
1274
|
+
return ctx.colid().accept(this);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// selectstmt
|
|
1278
|
+
// : select_no_parens
|
|
1279
|
+
// | select_with_parens
|
|
1280
|
+
// ;
|
|
1281
|
+
}, {
|
|
1282
|
+
key: "visitSelectstmt",
|
|
1283
|
+
value: function visitSelectstmt(ctx) {
|
|
1284
|
+
if (!ctx.select_no_parens()) {
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
return ctx.select_no_parens().accept(this);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// select_no_parens
|
|
1291
|
+
// : select_clause opt_sort_clause (for_locking_clause opt_select_limit | select_limit opt_for_locking_clause)?
|
|
1292
|
+
// | with_clause select_clause opt_sort_clause (for_locking_clause opt_select_limit | select_limit opt_for_locking_clause)?
|
|
1293
|
+
// ;
|
|
1294
|
+
}, {
|
|
1295
|
+
key: "visitSelect_no_parens",
|
|
1296
|
+
value: function visitSelect_no_parens(ctx) {
|
|
1297
|
+
return ctx.select_clause().accept(this);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// select_clause
|
|
1301
|
+
// : simple_select
|
|
1302
|
+
// | select_with_parens
|
|
1303
|
+
// ;
|
|
1304
|
+
}, {
|
|
1305
|
+
key: "visitSelect_clause",
|
|
1306
|
+
value: function visitSelect_clause(ctx) {
|
|
1307
|
+
return ctx.simple_select().accept(this);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// simple_select
|
|
1311
|
+
// : ( SELECT (opt_all_clause into_clause opt_target_list | distinct_clause target_list)
|
|
1312
|
+
// into_clause
|
|
1313
|
+
// from_clause
|
|
1314
|
+
// where_clause
|
|
1315
|
+
// group_clause
|
|
1316
|
+
// having_clause
|
|
1317
|
+
// window_clause
|
|
1318
|
+
// | values_clause
|
|
1319
|
+
// | TABLE relation_expr
|
|
1320
|
+
// | select_with_parens set_operator_with_all_or_distinct (simple_select | select_with_parens)
|
|
1321
|
+
// )
|
|
1322
|
+
// (set_operator_with_all_or_distinct (simple_select | select_with_parens))*
|
|
1323
|
+
// ;
|
|
1324
|
+
}, {
|
|
1325
|
+
key: "visitSimple_select",
|
|
1326
|
+
value: function visitSimple_select(ctx) {
|
|
1327
|
+
if (!ctx.values_clause()) {
|
|
1328
|
+
return null;
|
|
1329
|
+
}
|
|
1330
|
+
return ctx.values_clause().accept(this);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// values_clause
|
|
1334
|
+
// : VALUES OPEN_PAREN expr_list CLOSE_PAREN (COMMA OPEN_PAREN expr_list CLOSE_PAREN)*
|
|
1335
|
+
// ;
|
|
1336
|
+
}, {
|
|
1337
|
+
key: "visitValues_clause",
|
|
1338
|
+
value: function visitValues_clause(ctx) {
|
|
1339
|
+
var _this13 = this;
|
|
1340
|
+
return ctx.expr_list().map(function (expr) {
|
|
1341
|
+
var rawValues = expr.accept(_this13);
|
|
1342
|
+
|
|
1343
|
+
// We get the value of the c_expr through:
|
|
1344
|
+
// a_expr->a_expr_qual->a_expr_lessless->a_expr_or->a_expr_and->
|
|
1345
|
+
// a_expr_between->a_expr_in->a_expr_unary_not->a_expr_isnull->a_expr_is_not->
|
|
1346
|
+
// a_expr_compare->a_expr_like->a_expr_qual_op->a_expr_unary_qualop->a_expr_add->
|
|
1347
|
+
// a_expr_mul->a_expr_caret->a_expr_unary_sign->a_expr_at_time_zone->a_expr_collate->
|
|
1348
|
+
// a_expr_typecast
|
|
1349
|
+
var FLATTEN_DEPTH = 21;
|
|
1350
|
+
var rawRowValues = (0, _lodash.flattenDepth)(rawValues, FLATTEN_DEPTH);
|
|
1351
|
+
|
|
1352
|
+
// [
|
|
1353
|
+
// { value: '1', type: 'number' },
|
|
1354
|
+
// undefined,
|
|
1355
|
+
// {
|
|
1356
|
+
// value: '{"theme": "dark", "notifications": true}',
|
|
1357
|
+
// type: 'string',
|
|
1358
|
+
// type_name: 'JSONB',
|
|
1359
|
+
// schemaName: null
|
|
1360
|
+
// },
|
|
1361
|
+
// undefined,
|
|
1362
|
+
// ]
|
|
1363
|
+
return rawRowValues;
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// a_expr_collate
|
|
1368
|
+
// : a_expr_typecast (COLLATE any_name)?
|
|
1369
|
+
// ;
|
|
1370
|
+
}, {
|
|
1371
|
+
key: "visitA_expr_collate",
|
|
1372
|
+
value: function visitA_expr_collate(ctx) {
|
|
1373
|
+
var expressionValueSet = ctx.a_expr_typecast().accept(this);
|
|
1374
|
+
|
|
1375
|
+
// Possible values
|
|
1376
|
+
// 1: [ { value: 'inactive', type: 'string' } ]
|
|
1377
|
+
// 2: [
|
|
1378
|
+
// { value: '2021-01-05 18:45:00+00', type: 'string' },
|
|
1379
|
+
// undefined,
|
|
1380
|
+
// { type_name: 'TIMESTAMPTZ', schemaName: null }
|
|
1381
|
+
// ]
|
|
1382
|
+
// eslint-disable-next-line no-unused-vars
|
|
1383
|
+
var _expressionValueSet = _slicedToArray(expressionValueSet, 3),
|
|
1384
|
+
rawValue = _expressionValueSet[0],
|
|
1385
|
+
_ = _expressionValueSet[1],
|
|
1386
|
+
_expressionValueSet$ = _expressionValueSet[2],
|
|
1387
|
+
rawType = _expressionValueSet$ === void 0 ? {} : _expressionValueSet$;
|
|
1388
|
+
var value = rawValue.value,
|
|
1389
|
+
type = rawValue.type;
|
|
1390
|
+
return _objectSpread({
|
|
1391
|
+
value: value,
|
|
1392
|
+
type: type
|
|
1393
|
+
}, rawType);
|
|
1394
|
+
}
|
|
1164
1395
|
}]);
|
|
1165
1396
|
return PostgresASTGen;
|
|
1166
1397
|
}(_PostgreSQLParserVisitor["default"]);
|