@dbml/core 5.1.0 → 5.2.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 (53) hide show
  1. package/lib/export/DbmlExporter.js +3 -2
  2. package/lib/export/MysqlExporter.js +2 -2
  3. package/lib/export/OracleExporter.js +2 -2
  4. package/lib/export/PostgresExporter.js +2 -2
  5. package/lib/export/SqlServerExporter.js +2 -2
  6. package/lib/model_structure/element.js +1 -3
  7. package/lib/parse/ANTLR/ASTGeneration/AST.js +0 -2
  8. package/lib/parse/ANTLR/ASTGeneration/constants.js +1 -0
  9. package/lib/parse/ANTLR/ASTGeneration/index.js +16 -3
  10. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +1 -1
  11. package/lib/parse/ANTLR/ASTGeneration/mssql/README.md +157 -0
  12. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +1 -1
  13. package/lib/parse/ANTLR/ASTGeneration/mysql/README.md +157 -0
  14. package/lib/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.js +1154 -0
  15. package/lib/parse/ANTLR/ASTGeneration/oraclesql/README.md +157 -0
  16. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +2 -3
  17. package/lib/parse/ANTLR/ASTGeneration/postgres/README.md +157 -0
  18. package/lib/parse/ANTLR/ASTGeneration/snowflake/README.md +157 -0
  19. package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +1 -1
  20. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +60 -2
  21. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +25 -4
  22. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +1235 -1171
  23. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +2306 -2300
  24. package/lib/parse/ANTLR/parsers/mysql/MySqlLexerBase.js +52 -0
  25. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +6 -4
  26. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +15 -3
  27. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +2 -2
  28. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +2306 -2300
  29. package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +1 -1
  30. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.g4 +2623 -0
  31. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.interp +7475 -0
  32. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.js +3 -0
  33. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.tokens +4934 -0
  34. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexerBase.js +35 -0
  35. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.g4 +9988 -0
  36. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.interp +6174 -0
  37. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.js +3 -0
  38. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.tokens +4934 -0
  39. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserBase.js +64 -0
  40. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserVisitor.js +8466 -0
  41. package/lib/parse/Parser.js +8 -0
  42. package/lib/parse/buildParser.js +1 -1
  43. package/lib/parse/databaseGenerator.js +2 -2
  44. package/lib/parse/error.js +0 -1
  45. package/lib/parse/mssql/fk_definition/actions.js +1 -1
  46. package/lib/parse/mssql/index.js +0 -1
  47. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -1
  48. package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -2
  49. package/lib/parse/mssql/statements/statement_types/comments/index.js +2 -2
  50. package/lib/parse/mssql/utils.js +0 -1
  51. package/package.json +16 -5
  52. package/types/import/index.d.ts +1 -1
  53. package/types/parse/Parser.d.ts +3 -1
@@ -0,0 +1,1154 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _lodash = require("lodash");
9
+ var _AST = require("../AST");
10
+ var _constants = require("../constants");
11
+ var _helpers = require("../helpers");
12
+ var _error = require("../../../error");
13
+ var _OracleSqlParserVisitor = _interopRequireDefault(require("../../parsers/oraclesql/OracleSqlParserVisitor"));
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
19
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
21
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
22
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
23
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
25
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
26
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
27
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
28
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
29
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
30
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
31
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
32
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
34
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
35
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
36
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
37
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
38
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
39
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
40
+ // We cannot use TABLE_CONSTRAINT_KIND and COLUMN_CONSTRAINT_KIND from '../constants' as their values are indistinguishable from each other
41
+ // For example: TABLE_CONSTRAINT_KIND.UNIQUE === COLUMN_CONSTRAINT_KIND.UNIQUE
42
+ // Therefore, we redefine them to be different
43
+ // TODO: Migrate the other parser to use our version instead
44
+ var TABLE_CONSTRAINT_KIND = {
45
+ FIELD: 'table_field',
46
+ INDEX: 'table_index',
47
+ FK: 'table_fk',
48
+ UNIQUE: 'table_unique',
49
+ PK: 'table_pk',
50
+ DEFAULT: 'table_default',
51
+ CHECK: 'table_check'
52
+ };
53
+ var COLUMN_CONSTRAINT_KIND = {
54
+ NOT_NULL: 'col_not_null',
55
+ NULLABLE: 'col_nullable',
56
+ UNIQUE: 'col_unique',
57
+ PK: 'col_pk',
58
+ DEFAULT: 'col_dbdefault',
59
+ INCREMENT: 'col_increment',
60
+ INLINE_REF: 'col_inline_ref',
61
+ NOTE: 'col_note',
62
+ CHECK: 'col_check'
63
+ };
64
+ var findTable = function findTable(tables, schemaName, tableName) {
65
+ var realSchemaName = schemaName || null;
66
+ var table = tables.find(function (table) {
67
+ var targetSchemaName = table.schemaName || null;
68
+ return targetSchemaName === realSchemaName && table.name === tableName;
69
+ });
70
+ return table;
71
+ };
72
+ var findColumn = function findColumn(table, columnName) {
73
+ var column = table.fields.find(function (field) {
74
+ return field.name === columnName;
75
+ });
76
+ return column;
77
+ };
78
+
79
+ // `e` is the value returned by `visitExpression`
80
+ var processDefaultExpression = function processDefaultExpression(e) {
81
+ return {
82
+ value: e.type !== _constants.CONSTRAINT_TYPE.COLUMN ? e.value : e.rawValue,
83
+ type: e.type !== _constants.CONSTRAINT_TYPE.COLUMN ? e.type : _constants.DATA_TYPE.EXPRESSION
84
+ };
85
+ };
86
+
87
+ // `e` is the value returned by `visitExpression`
88
+ var processIndexExpression = function processIndexExpression(e) {
89
+ var type;
90
+ switch (e.type) {
91
+ case _constants.CONSTRAINT_TYPE.COLUMN:
92
+ type = _constants.CONSTRAINT_TYPE.COLUMN;
93
+ break;
94
+ case _constants.DATA_TYPE.STRING:
95
+ type = _constants.CONSTRAINT_TYPE.STRING;
96
+ break;
97
+ default:
98
+ type = _constants.CONSTRAINT_TYPE.EXPRESSION;
99
+ break;
100
+ }
101
+ return {
102
+ value: e.value.toString(),
103
+ type: type
104
+ };
105
+ };
106
+ var createCompilerError = function createCompilerError(ctx, message) {
107
+ return _error.CompilerError.create([{
108
+ message: message,
109
+ location: {
110
+ start: {
111
+ line: ctx.start.line,
112
+ column: ctx.start.column + 1
113
+ },
114
+ end: {
115
+ line: ctx.stop.line,
116
+ column: ctx.stop.column + (0, _helpers.getOriginalText)(ctx).length + 1
117
+ }
118
+ }
119
+ }]);
120
+ };
121
+
122
+ // Only methods for rules representing whole statements can mutate `data`:
123
+ // * create_table
124
+ // * alter_table
125
+ // * create_index
126
+ // * insert_statement
127
+ // All other methods must be pure
128
+ var OracleSqlASTGen = exports["default"] = /*#__PURE__*/function (_OracleSqlParserVisit) {
129
+ function OracleSqlASTGen() {
130
+ var _this;
131
+ _classCallCheck(this, OracleSqlASTGen);
132
+ _this = _callSuper(this, OracleSqlASTGen);
133
+ _this.data = {
134
+ schemas: [],
135
+ tables: [],
136
+ refs: [],
137
+ enums: [],
138
+ tableGroups: [],
139
+ aliases: [],
140
+ project: {},
141
+ records: []
142
+ };
143
+ return _this;
144
+ }
145
+
146
+ // sql_script
147
+ // : sql_plus_command_no_semicolon? (
148
+ // (((sql_plus_command SEMICOLON? '/'?) | (unit_statement SEMICOLON '/'?))* (sql_plus_command | unit_statement)) SEMICOLON? '/'?
149
+ // )? EOF
150
+ // ;
151
+ _inherits(OracleSqlASTGen, _OracleSqlParserVisit);
152
+ return _createClass(OracleSqlASTGen, [{
153
+ key: "visitSql_script",
154
+ value: function visitSql_script(ctx) {
155
+ var _ctx$unit_statement,
156
+ _this2 = this;
157
+ (_ctx$unit_statement = ctx.unit_statement()) === null || _ctx$unit_statement === void 0 || _ctx$unit_statement.forEach(function (stmt) {
158
+ return stmt.accept(_this2);
159
+ });
160
+ return this.data;
161
+ }
162
+
163
+ // unit_statement
164
+ // : create_table
165
+ // | comment_on_table
166
+ // | comment_on_column
167
+ // | alter_table
168
+ // | create_index
169
+ // | data_manipulation_language_statements
170
+ // | <other rules>
171
+ // ;
172
+ }, {
173
+ key: "visitUnit_statement",
174
+ value: function visitUnit_statement(ctx) {
175
+ if (ctx.create_table()) {
176
+ ctx.create_table().accept(this);
177
+ } else if (ctx.comment_on_table()) {
178
+ ctx.comment_on_table().accept(this);
179
+ } else if (ctx.comment_on_column()) {
180
+ ctx.comment_on_column().accept(this);
181
+ } else if (ctx.alter_table()) {
182
+ ctx.alter_table().accept(this);
183
+ } else if (ctx.create_index()) {
184
+ ctx.create_index().accept(this);
185
+ } else if (ctx.data_manipulation_language_statements()) {
186
+ ctx.data_manipulation_language_statements().accept(this);
187
+ }
188
+ }
189
+
190
+ // data_manipulation_language_statements
191
+ // : insert_statement
192
+ // | <other rules>
193
+ // ;
194
+ }, {
195
+ key: "visitData_manipulation_language_statements",
196
+ value: function visitData_manipulation_language_statements(ctx) {
197
+ if (ctx.insert_statement()) {
198
+ ctx.insert_statement().accept(this);
199
+ }
200
+ }
201
+
202
+ // create_table
203
+ // : CREATE TABLE (schema_name '.')? table_name
204
+ // (relational_table | <other rules>)
205
+ // | <other rules>
206
+ // ;
207
+ }, {
208
+ key: "visitCreate_table",
209
+ value: function visitCreate_table(ctx) {
210
+ var tableName = ctx.table_name().accept(this);
211
+ var schemaName = ctx.schema_name() ? ctx.schema_name().accept(this) : undefined;
212
+ if (ctx.relational_table()) {
213
+ var _this$data$refs, _this$data$refs2;
214
+ var tableElements = ctx.relational_table().accept(this);
215
+ var _tableElements$reduce = tableElements.reduce(function (acc, ele) {
216
+ var _acc$;
217
+ if (ele.type === TABLE_CONSTRAINT_KIND.FIELD) acc[0].push(ele.value);else if ([TABLE_CONSTRAINT_KIND.INDEX, TABLE_CONSTRAINT_KIND.UNIQUE, TABLE_CONSTRAINT_KIND.PK].includes(ele.type)) acc[1].push(ele.value);else if (ele.type === TABLE_CONSTRAINT_KIND.FK) acc[2].push(ele.value);else if (ele.type === TABLE_CONSTRAINT_KIND.CHECK) (_acc$ = acc[3]).push.apply(_acc$, _toConsumableArray(ele.value.checks));
218
+ return acc;
219
+ }, [[], [], [], []]),
220
+ _tableElements$reduce2 = _slicedToArray(_tableElements$reduce, 4),
221
+ fieldsData = _tableElements$reduce2[0],
222
+ indexes = _tableElements$reduce2[1],
223
+ tableRefs = _tableElements$reduce2[2],
224
+ tableChecks = _tableElements$reduce2[3];
225
+ (_this$data$refs = this.data.refs).push.apply(_this$data$refs, _toConsumableArray((0, _lodash.flatten)(fieldsData.map(function (fieldData) {
226
+ return fieldData.inline_refs.map(function (inlineRef) {
227
+ inlineRef.endpoints[0].tableName = tableName;
228
+ inlineRef.endpoints[0].schemaName = schemaName;
229
+ inlineRef.endpoints[0].fieldNames = [fieldData.field.name];
230
+ return inlineRef;
231
+ });
232
+ }))));
233
+ (_this$data$refs2 = this.data.refs).push.apply(_this$data$refs2, _toConsumableArray(tableRefs.map(function (tableRef) {
234
+ tableRef.endpoints[0].tableName = tableName;
235
+ tableRef.endpoints[0].schemaName = schemaName;
236
+ return tableRef;
237
+ })));
238
+ this.data.tables.push(new _AST.Table({
239
+ name: tableName,
240
+ schemaName: schemaName,
241
+ fields: fieldsData.map(function (fd) {
242
+ return fd.field;
243
+ }),
244
+ indexes: indexes,
245
+ checks: tableChecks
246
+ }));
247
+ }
248
+ }
249
+
250
+ // relational_table
251
+ // : ('(' relational_property (',' relational_property)* ')')? relational_table_properties?
252
+ // ;
253
+ }, {
254
+ key: "visitRelational_table",
255
+ value: function visitRelational_table(ctx) {
256
+ var _this3 = this;
257
+ if (ctx.relational_property()) {
258
+ return ctx.relational_property().map(function (p) {
259
+ return p.accept(_this3);
260
+ });
261
+ }
262
+ return [];
263
+ }
264
+
265
+ // relational_property
266
+ // : column_definition
267
+ // | out_of_line_constraint
268
+ // | out_of_line_ref_constraint
269
+ // | <other rules>
270
+ // ;
271
+ }, {
272
+ key: "visitRelational_property",
273
+ value: function visitRelational_property(ctx) {
274
+ if (ctx.column_definition()) {
275
+ return ctx.column_definition().accept(this);
276
+ }
277
+ if (ctx.out_of_line_constraint()) {
278
+ return ctx.out_of_line_constraint().accept(this);
279
+ }
280
+ if (ctx.out_of_line_ref_constraint()) {
281
+ return ctx.out_of_line_ref_constraint().accept(this);
282
+ }
283
+ return null;
284
+ }
285
+
286
+ // column_definition
287
+ // : column_name ((datatype | type_name) (COLLATE column_collation_name)?)? SORT? (
288
+ // VISIBLE
289
+ // | INVISIBLE
290
+ // )? (DEFAULT (ON NULL_)? expression | identity_clause)? (ENCRYPT encryption_spec)? (
291
+ // inline_constraint+
292
+ // | inline_ref_constraint
293
+ // )? annotations_clause?
294
+ // ;
295
+ }, {
296
+ key: "visitColumn_definition",
297
+ value: function visitColumn_definition(ctx) {
298
+ var _ctx$datatype,
299
+ _ctx$type_name,
300
+ _this4 = this;
301
+ var name = (0, _lodash.last)(ctx.column_name().accept(this));
302
+ var type = ((_ctx$datatype = ctx.datatype()) === null || _ctx$datatype === void 0 ? void 0 : _ctx$datatype.accept(this)) || ((_ctx$type_name = ctx.type_name()) === null || _ctx$type_name === void 0 ? void 0 : _ctx$type_name.accept(this));
303
+ if (!type) throw createCompilerError(ctx, 'Importing a column definition without a type is not supported');
304
+ var constraints = (ctx.inline_constraint() || []).map(function (c) {
305
+ return c.accept(_this4);
306
+ }).filter(Boolean);
307
+ if (ctx.DEFAULT()) {
308
+ var value = ctx.expression().accept(this);
309
+ constraints.push({
310
+ type: COLUMN_CONSTRAINT_KIND.DEFAULT,
311
+ value: {
312
+ dbdefault: processDefaultExpression(value)
313
+ }
314
+ });
315
+ }
316
+ if (ctx.identity_clause()) {
317
+ constraints.push({
318
+ type: COLUMN_CONSTRAINT_KIND.INCREMENT,
319
+ value: {
320
+ increment: true
321
+ }
322
+ });
323
+ }
324
+ var settings = {
325
+ checks: [],
326
+ inline_refs: []
327
+ };
328
+ constraints.forEach(function (constraint) {
329
+ var _settings$checks, _settings$inline_refs;
330
+ switch (constraint.type) {
331
+ case COLUMN_CONSTRAINT_KIND.DEFAULT:
332
+ settings.dbdefault = constraint.value.dbdefault;
333
+ break;
334
+ case COLUMN_CONSTRAINT_KIND.NOT_NULL:
335
+ settings.not_null = true;
336
+ break;
337
+ case COLUMN_CONSTRAINT_KIND.NULLABLE:
338
+ settings.not_null = false;
339
+ break;
340
+ case COLUMN_CONSTRAINT_KIND.PK:
341
+ settings.pk = true;
342
+ break;
343
+ case COLUMN_CONSTRAINT_KIND.UNIQUE:
344
+ settings.unique = true;
345
+ break;
346
+ case COLUMN_CONSTRAINT_KIND.CHECK:
347
+ (_settings$checks = settings.checks).push.apply(_settings$checks, _toConsumableArray(constraint.value.checks));
348
+ break;
349
+ case COLUMN_CONSTRAINT_KIND.INCREMENT:
350
+ settings.increment = true;
351
+ break;
352
+ case COLUMN_CONSTRAINT_KIND.FK:
353
+ (_settings$inline_refs = settings.inline_refs).push.apply(_settings$inline_refs, _toConsumableArray(constraint.value.inline_refs));
354
+ break;
355
+ default:
356
+ }
357
+ });
358
+ var field = new _AST.Field(_objectSpread({
359
+ name: name,
360
+ type: type
361
+ }, settings));
362
+ return {
363
+ type: TABLE_CONSTRAINT_KIND.FIELD,
364
+ value: {
365
+ field: field,
366
+ inline_refs: settings.inline_refs || []
367
+ }
368
+ };
369
+ }
370
+
371
+ // inline_constraint
372
+ // : constraint_name? (
373
+ // NOT? NULL_
374
+ // | (UNIQUE | PRIMARY) KEY?
375
+ // | references_clause
376
+ // | check_constraint
377
+ // ) constraint_state?
378
+ // ;
379
+ }, {
380
+ key: "visitInline_constraint",
381
+ value: function visitInline_constraint(ctx) {
382
+ var _ctx$constraint_name;
383
+ if (ctx.NULL_() && ctx.NOT()) {
384
+ return {
385
+ type: COLUMN_CONSTRAINT_KIND.NOT_NULL,
386
+ value: {
387
+ not_null: true
388
+ }
389
+ };
390
+ }
391
+ if (ctx.NULL_()) {
392
+ return {
393
+ type: COLUMN_CONSTRAINT_KIND.NULLABLE,
394
+ value: {
395
+ not_null: false
396
+ }
397
+ };
398
+ }
399
+ if (ctx.UNIQUE()) {
400
+ return {
401
+ type: COLUMN_CONSTRAINT_KIND.UNIQUE,
402
+ value: {
403
+ unique: true
404
+ }
405
+ };
406
+ }
407
+ if (ctx.PRIMARY()) {
408
+ return {
409
+ type: COLUMN_CONSTRAINT_KIND.PK,
410
+ value: {
411
+ pk: true
412
+ }
413
+ };
414
+ }
415
+ var name = (_ctx$constraint_name = ctx.constraint_name()) === null || _ctx$constraint_name === void 0 ? void 0 : _ctx$constraint_name.accept(this);
416
+ if (ctx.references_clause()) {
417
+ var ref = ctx.references_clause().accept(this);
418
+ ref.name = name;
419
+ return {
420
+ type: COLUMN_CONSTRAINT_KIND.FK,
421
+ value: {
422
+ inline_refs: [ref]
423
+ }
424
+ };
425
+ }
426
+ if (ctx.check_constraint()) {
427
+ var checkCtx = ctx.check_constraint();
428
+ checkCtx.isColumn = true;
429
+ var check = checkCtx.accept(this);
430
+ check.value.checks[0].name = name;
431
+ return check;
432
+ }
433
+ return null;
434
+ }
435
+
436
+ // out_of_line_constraint
437
+ // : (
438
+ // ((CONSTRAINT | CONSTRAINTS) constraint_name)? (
439
+ // UNIQUE '(' column_name (',' column_name)* ')'
440
+ // | PRIMARY KEY '(' column_name (',' column_name)* ')'
441
+ // | foreign_key_clause
442
+ // | CHECK '(' condition ')'
443
+ // )
444
+ // )
445
+ // constraint_state?
446
+ // parallel_clause?
447
+ // ;
448
+ }, {
449
+ key: "visitOut_of_line_constraint",
450
+ value: function visitOut_of_line_constraint(ctx) {
451
+ var _this5 = this;
452
+ if (ctx.UNIQUE()) {
453
+ var _ctx$constraint_name2;
454
+ var columns = ctx.column_name().map(function (c) {
455
+ return {
456
+ value: (0, _lodash.last)(c.accept(_this5)),
457
+ type: _constants.CONSTRAINT_TYPE.COLUMN
458
+ };
459
+ });
460
+ return {
461
+ type: TABLE_CONSTRAINT_KIND.UNIQUE,
462
+ value: new _AST.Index({
463
+ columns: columns,
464
+ unique: true,
465
+ name: (_ctx$constraint_name2 = ctx.constraint_name()) === null || _ctx$constraint_name2 === void 0 ? void 0 : _ctx$constraint_name2.accept(this)
466
+ })
467
+ };
468
+ }
469
+ if (ctx.PRIMARY()) {
470
+ var _ctx$constraint_name3;
471
+ var _columns = ctx.column_name().map(function (c) {
472
+ return {
473
+ value: (0, _lodash.last)(c.accept(_this5)),
474
+ type: _constants.CONSTRAINT_TYPE.COLUMN
475
+ };
476
+ });
477
+ return {
478
+ type: TABLE_CONSTRAINT_KIND.PK,
479
+ value: new _AST.Index({
480
+ columns: _columns,
481
+ pk: true,
482
+ name: (_ctx$constraint_name3 = ctx.constraint_name()) === null || _ctx$constraint_name3 === void 0 ? void 0 : _ctx$constraint_name3.accept(this)
483
+ })
484
+ };
485
+ }
486
+ if (ctx.foreign_key_clause()) {
487
+ var _ctx$constraint_name4;
488
+ var ref = ctx.foreign_key_clause().accept(this);
489
+ ref.value.name = (_ctx$constraint_name4 = ctx.constraint_name()) === null || _ctx$constraint_name4 === void 0 ? void 0 : _ctx$constraint_name4.accept(this);
490
+ return ref;
491
+ }
492
+ if (ctx.condition()) {
493
+ var _ctx$constraint_name5;
494
+ var expression = (0, _helpers.getOriginalText)(ctx.condition());
495
+ return {
496
+ type: TABLE_CONSTRAINT_KIND.CHECK,
497
+ value: {
498
+ checks: [{
499
+ name: (_ctx$constraint_name5 = ctx.constraint_name()) === null || _ctx$constraint_name5 === void 0 ? void 0 : _ctx$constraint_name5.accept(this),
500
+ expression: expression
501
+ }]
502
+ }
503
+ };
504
+ }
505
+ return null;
506
+ }
507
+
508
+ // out_of_line_ref_constraint
509
+ // : (CONSTRAINT constraint_name)? FOREIGN KEY '(' (','? ref_col_or_attr = regular_id)+ ')' references_clause constraint_state?
510
+ // | <other rules>
511
+ // ;
512
+ }, {
513
+ key: "visitOut_of_line_ref_constraint",
514
+ value: function visitOut_of_line_ref_constraint(ctx) {
515
+ var _ctx$constraint_name6,
516
+ _this6 = this;
517
+ var refName = (_ctx$constraint_name6 = ctx.constraint_name()) === null || _ctx$constraint_name6 === void 0 ? void 0 : _ctx$constraint_name6.accept(this);
518
+ var firstFieldNames = ctx.regular_id().map(function (c) {
519
+ return c.accept(_this6);
520
+ });
521
+ var ref = ctx.references_clause().accept(this);
522
+ ref.endpoints[0].fieldNames = firstFieldNames;
523
+ if (refName) {
524
+ ref.name = refName;
525
+ }
526
+ return {
527
+ type: TABLE_CONSTRAINT_KIND.FK,
528
+ value: ref
529
+ };
530
+ }
531
+
532
+ // foreign_key_clause
533
+ // : FOREIGN KEY paren_column_list references_clause on_delete_clause?
534
+ // ;
535
+ }, {
536
+ key: "visitForeign_key_clause",
537
+ value: function visitForeign_key_clause(ctx) {
538
+ var firstFieldNames = ctx.paren_column_list().accept(this).map(function (c) {
539
+ return (0, _lodash.last)(c);
540
+ });
541
+ var ref = ctx.references_clause().accept(this);
542
+ ref.endpoints[0].fieldNames = firstFieldNames;
543
+ if (ctx.on_delete_clause()) {
544
+ ref.onDelete = ctx.on_delete_clause().accept(this);
545
+ }
546
+ return {
547
+ type: TABLE_CONSTRAINT_KIND.FK,
548
+ value: ref
549
+ };
550
+ }
551
+
552
+ // references_clause
553
+ // : REFERENCES tableview_name paren_column_list? (ON DELETE (CASCADE | SET NULL_))?
554
+ // ;
555
+ }, {
556
+ key: "visitReferences_clause",
557
+ value: function visitReferences_clause(ctx) {
558
+ if (!ctx.paren_column_list()) throw createCompilerError(ctx.tableview_name(), 'Importing a foreign key with implicit referenced columns is not supported');
559
+ var names = ctx.tableview_name().accept(this);
560
+ var refTableName = (0, _lodash.last)(names);
561
+ var refSchemaName = names.length > 1 ? names[names.length - 2] : undefined;
562
+ var secondFieldNames = ctx.paren_column_list().accept(this).map(function (c) {
563
+ return (0, _lodash.last)(c);
564
+ });
565
+ return new _AST.Ref({
566
+ endpoints: [new _AST.Endpoint({
567
+ tableName: null,
568
+ schemaName: null,
569
+ fieldNames: [],
570
+ relation: '*'
571
+ }), new _AST.Endpoint({
572
+ tableName: refTableName,
573
+ schemaName: refSchemaName,
574
+ fieldNames: secondFieldNames,
575
+ relation: '1'
576
+ })]
577
+ });
578
+ }
579
+
580
+ // on_delete_clause
581
+ // : ON DELETE (CASCADE | SET NULL_)
582
+ // ;
583
+ }, {
584
+ key: "visitOn_delete_clause",
585
+ value: function visitOn_delete_clause(ctx) {
586
+ if (ctx.CASCADE()) return 'cascade';
587
+ if (ctx.SET() && ctx.NULL_()) return 'set null';
588
+ return null;
589
+ }
590
+
591
+ // check_constraint
592
+ // : CHECK '(' condition ')'
593
+ // ;
594
+ }, {
595
+ key: "visitCheck_constraint",
596
+ value: function visitCheck_constraint(ctx) {
597
+ var expression = (0, _helpers.getOriginalText)(ctx.condition());
598
+ return {
599
+ type: ctx.isColumn ? COLUMN_CONSTRAINT_KIND.CHECK : TABLE_CONSTRAINT_KIND.CHECK,
600
+ value: {
601
+ checks: [{
602
+ expression: expression
603
+ }]
604
+ }
605
+ };
606
+ }
607
+ }, {
608
+ key: "visitColumn_list",
609
+ value: function visitColumn_list(ctx) {
610
+ var _this7 = this;
611
+ return ctx.column_name().map(function (c) {
612
+ return c.accept(_this7);
613
+ });
614
+ }
615
+
616
+ // tableview_name
617
+ // : identifier ('.' id_expression)? (
618
+ // AT_SIGN link_name
619
+ // | /*TODO{!(input.LA(2) == BY)}?*/ partition_extension_clause
620
+ // )?
621
+ // | xmltable outer_join_sign?
622
+ // ;
623
+ }, {
624
+ key: "visitTableview_name",
625
+ value: function visitTableview_name(ctx) {
626
+ var schema = ctx.id_expression() ? [ctx.identifier().accept(this)] : [];
627
+ var table = ctx.id_expression() ? ctx.id_expression().accept(this) : ctx.identifier().accept(this);
628
+ return [].concat(schema, [table]);
629
+ }
630
+ }, {
631
+ key: "visitSchema_name",
632
+ value: function visitSchema_name(ctx) {
633
+ return ctx.identifier().accept(this);
634
+ }
635
+ }, {
636
+ key: "visitTable_name",
637
+ value: function visitTable_name(ctx) {
638
+ return ctx.identifier().accept(this);
639
+ }
640
+ }, {
641
+ key: "visitColumn_name",
642
+ value: function visitColumn_name(ctx) {
643
+ var _this8 = this;
644
+ return [ctx.identifier().accept(this)].concat(ctx.id_expression().map(function (i) {
645
+ return i.accept(_this8);
646
+ }));
647
+ }
648
+ }, {
649
+ key: "visitIdentifier",
650
+ value: function visitIdentifier(ctx) {
651
+ var text = (0, _helpers.getOriginalText)(ctx);
652
+ if (text.startsWith('"')) {
653
+ return text.substring(1, text.length - 1);
654
+ }
655
+ text.replace('""', '"');
656
+ return text;
657
+ }
658
+ }, {
659
+ key: "visitType_name",
660
+ value: function visitType_name(ctx) {
661
+ var _this9 = this;
662
+ var names = ctx.id_expression().map(function (i) {
663
+ return i.accept(_this9);
664
+ });
665
+ var typeName = (0, _lodash.last)(names);
666
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
667
+ return {
668
+ type_name: typeName,
669
+ schemaName: schemaName
670
+ };
671
+ }
672
+ }, {
673
+ key: "visitDatatype",
674
+ value: function visitDatatype(ctx) {
675
+ var typeName = (0, _helpers.getOriginalText)(ctx);
676
+ return {
677
+ type_name: typeName
678
+ };
679
+ }
680
+
681
+ // comment_on_table
682
+ // : COMMENT ON TABLE tableview_name IS quoted_string
683
+ // ;
684
+ }, {
685
+ key: "visitComment_on_table",
686
+ value: function visitComment_on_table(ctx) {
687
+ var names = ctx.tableview_name().accept(this);
688
+ var tableName = (0, _lodash.last)(names);
689
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
690
+ var table = findTable(this.data.tables, schemaName, tableName);
691
+ if (!table) {
692
+ throw createCompilerError(ctx.tableview_name(), "Table \"".concat(tableName, "\" not found"));
693
+ }
694
+ var note = ctx.quoted_string().accept(this);
695
+ table.note = {
696
+ value: note
697
+ };
698
+ }
699
+
700
+ // comment_on_column
701
+ // : COMMENT ON COLUMN column_name IS quoted_string
702
+ // ;
703
+ }, {
704
+ key: "visitComment_on_column",
705
+ value: function visitComment_on_column(ctx) {
706
+ var names = ctx.column_name().accept(this);
707
+ var columnName = (0, _lodash.last)(names);
708
+ names.pop();
709
+ var tableName = (0, _lodash.last)(names);
710
+ names.pop();
711
+ var schemaName = (0, _lodash.last)(names);
712
+ var table = findTable(this.data.tables, schemaName, tableName);
713
+ if (!table) {
714
+ throw createCompilerError(ctx.column_name(), "Table \"".concat(tableName, "\" not found"));
715
+ }
716
+ var field = findColumn(table, columnName);
717
+ if (!field) {
718
+ throw createCompilerError(ctx.column_name(), "Column \"".concat(columnName, "\" not found in table \"").concat(tableName, "\""));
719
+ }
720
+ var note = ctx.quoted_string().accept(this);
721
+ field.note = {
722
+ value: note
723
+ };
724
+ }
725
+
726
+ // alter_table
727
+ // : ALTER TABLE tableview_name memoptimize_read_write_clause* (constraint_clauses | column_clauses | <other rules>) ((enable_disable_clause | enable_or_disable (TABLE LOCK | ALL TRIGGERS))+)?
728
+
729
+ // ;
730
+ }, {
731
+ key: "visitAlter_table",
732
+ value: function visitAlter_table(ctx) {
733
+ var _this0 = this;
734
+ var names = ctx.tableview_name().accept(this);
735
+ var tableName = (0, _lodash.last)(names);
736
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
737
+ var table = findTable(this.data.tables, schemaName, tableName);
738
+ if (!table) {
739
+ throw createCompilerError(ctx.tableview_name(), "Table \"".concat(tableName, "\" not found"));
740
+ }
741
+ function handleConstraint(column, constraint) {
742
+ var _table$checks, _column$checks;
743
+ switch (constraint.type) {
744
+ case TABLE_CONSTRAINT_KIND.FK:
745
+ case COLUMN_CONSTRAINT_KIND.FK:
746
+ constraint.value.endpoints[0].tableName = tableName;
747
+ constraint.value.endpoints[0].schemaName = schemaName;
748
+ this.data.refs.push(constraint.value);
749
+ break;
750
+ case TABLE_CONSTRAINT_KIND.CHECK:
751
+ if (!table.checks) table.checks = [];
752
+ (_table$checks = table.checks).push.apply(_table$checks, _toConsumableArray(constraint.value.checks));
753
+ break;
754
+ case COLUMN_CONSTRAINT_KIND.CHECK:
755
+ if (!column.checks) table.checks = [];
756
+ (_column$checks = column.checks).push.apply(_column$checks, _toConsumableArray(constraint.value.checks));
757
+ break;
758
+ case COLUMN_CONSTRAINT_KIND.PK:
759
+ column.pk = true;
760
+ column.unique = undefined;
761
+ break;
762
+ case COLUMN_CONSTRAINT_KIND.UNIQUE:
763
+ column.unique = true;
764
+ break;
765
+ case TABLE_CONSTRAINT_KIND.UNIQUE:
766
+ case TABLE_CONSTRAINT_KIND.INDEX:
767
+ case TABLE_CONSTRAINT_KIND.PK:
768
+ if (!table.indexes) table.indexes = [];
769
+ table.indexes.push(constraint.value);
770
+ break;
771
+ case COLUMN_CONSTRAINT_KIND.DEFAULT:
772
+ column.dbdefault = constraint.value.dbdefault;
773
+ break;
774
+ case COLUMN_CONSTRAINT_KIND.NOT_NULL:
775
+ column.not_null = true;
776
+ break;
777
+ case COLUMN_CONSTRAINT_KIND.NULLABLE:
778
+ column.not_null = false;
779
+ break;
780
+ case COLUMN_CONSTRAINT_KIND.INCREMENT:
781
+ column.increment = true;
782
+ break;
783
+ default:
784
+ }
785
+ }
786
+ if (ctx.constraint_clauses() || ctx.column_clauses()) {
787
+ var res = ctx.constraint_clauses() ? [{
788
+ column: null,
789
+ constraints: ctx.constraint_clauses().accept(this)
790
+ }] : ctx.column_clauses().accept(this);
791
+ res.forEach(function (r) {
792
+ var column = r.column !== null ? findColumn(table, r.column) : null;
793
+ if (r.column !== null && !column) {
794
+ throw createCompilerError(ctx.tableview_name(), "Column \"".concat(r.column, "\" not found on Table \"").concat(tableName, "\""));
795
+ }
796
+ r.constraints.forEach(function (c) {
797
+ return handleConstraint.bind(_this0)(column, c);
798
+ });
799
+ });
800
+ }
801
+ }
802
+
803
+ // column_clauses
804
+ // : add_modify_drop_column_clauses
805
+ // | <other rules>
806
+ // ;
807
+ }, {
808
+ key: "visitColumn_clauses",
809
+ value: function visitColumn_clauses(ctx) {
810
+ if (ctx.add_modify_drop_column_clauses()) {
811
+ return ctx.add_modify_drop_column_clauses().accept(this);
812
+ }
813
+ return [];
814
+ }
815
+
816
+ // add_modify_drop_column_clauses
817
+ // : (constraint_clauses | add_column_clause | modify_column_clauses | drop_column_clause)+
818
+ // ;
819
+ }, {
820
+ key: "visitAdd_modify_drop_column_clauses",
821
+ value: function visitAdd_modify_drop_column_clauses(ctx) {
822
+ var _this1 = this;
823
+ var constraints = [];
824
+ if (ctx.constraint_clauses()) {
825
+ constraints.push({
826
+ column: null,
827
+ constraints: ctx.constraint_clauses().flatMap(function (c) {
828
+ return c.accept(_this1);
829
+ })
830
+ });
831
+ }
832
+ if (ctx.modify_column_clauses()) {
833
+ constraints.push.apply(constraints, _toConsumableArray(ctx.modify_column_clauses().flatMap(function (c) {
834
+ return c.accept(_this1);
835
+ })));
836
+ }
837
+ return constraints;
838
+ }
839
+
840
+ // modify_column_clauses
841
+ // : MODIFY (
842
+ // '(' modify_col_properties (',' modify_col_properties)* ')'
843
+ // | '(' modify_col_visibility (',' modify_col_visibility)* ')'
844
+ // | modify_col_properties
845
+ // | modify_col_visibility
846
+ // | modify_col_substitutable
847
+ // )
848
+ // ;
849
+ }, {
850
+ key: "visitModify_column_clauses",
851
+ value: function visitModify_column_clauses(ctx) {
852
+ var _this10 = this;
853
+ return ctx.modify_col_properties().map(function (c) {
854
+ return c.accept(_this10);
855
+ });
856
+ }
857
+
858
+ // modify_col_properties
859
+ // : column_name datatype? (DEFAULT (ON NULL_)? expression)? (ENCRYPT encryption_spec | DECRYPT)? inline_constraint* lob_storage_clause? annotations_clause?
860
+ // ;
861
+ }, {
862
+ key: "visitModify_col_properties",
863
+ value: function visitModify_col_properties(ctx) {
864
+ var _this11 = this;
865
+ var constraints = [];
866
+ var columnName = (0, _lodash.last)(ctx.column_name().accept(this));
867
+ if (ctx.DEFAULT()) {
868
+ var expression = ctx.expression().accept(this);
869
+ constraints.push({
870
+ type: COLUMN_CONSTRAINT_KIND.DEFAULT,
871
+ value: {
872
+ dbdefault: processDefaultExpression(expression)
873
+ }
874
+ });
875
+ } else if (ctx.inline_constraint()) {
876
+ constraints.push.apply(constraints, _toConsumableArray(ctx.inline_constraint().map(function (c) {
877
+ return c.accept(_this11);
878
+ })));
879
+ }
880
+ return {
881
+ column: columnName,
882
+ constraints: constraints
883
+ };
884
+ }
885
+
886
+ // constraint_clauses
887
+ // : ADD '(' (out_of_line_constraint (',' out_of_line_constraint)* | out_of_line_ref_constraint) ')'
888
+ // | ADD (out_of_line_constraint | out_of_line_ref_constraint)
889
+ // | <other rules>
890
+ // ;
891
+ }, {
892
+ key: "visitConstraint_clauses",
893
+ value: function visitConstraint_clauses(ctx) {
894
+ var _this12 = this;
895
+ if (ctx.out_of_line_constraint()) {
896
+ return ctx.out_of_line_constraint().map(function (c) {
897
+ return c.accept(_this12);
898
+ }).filter(Boolean);
899
+ }
900
+ if (ctx.out_of_line_ref_constraint()) {
901
+ return [ctx.out_of_line_ref_constraint().accept(this)];
902
+ }
903
+ return [];
904
+ }
905
+
906
+ // create_index
907
+ // : CREATE (UNIQUE | BITMAP)? INDEX index_name (IF NOT EXISTS)? ON (
908
+ // cluster_index_clause
909
+ // | table_index_clause
910
+ // | bitmap_join_index_clause
911
+ // ) (USABLE | UNUSABLE)? ((DEFERRED | IMMEDIATE) INVALIDATION)?
912
+ // ;
913
+ }, {
914
+ key: "visitCreate_index",
915
+ value: function visitCreate_index(ctx) {
916
+ if (!ctx.table_index_clause()) return;
917
+ var unique = !!ctx.UNIQUE();
918
+ var bitmap = !!ctx.BITMAP();
919
+ var indexName = ctx.index_name().accept(this);
920
+ var _ctx$table_index_clau = ctx.table_index_clause().accept(this),
921
+ names = _ctx$table_index_clau.names,
922
+ columns = _ctx$table_index_clau.columns;
923
+ var tableName = (0, _lodash.last)(names);
924
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
925
+ var table = findTable(this.data.tables, schemaName, tableName);
926
+ if (!table) {
927
+ throw createCompilerError(ctx.table_index_clause(), "Table ".concat(tableName, " not found"));
928
+ }
929
+ if (!table.indexes) table.indexes = [];
930
+ table.indexes.push(new _AST.Index({
931
+ name: indexName,
932
+ columns: columns,
933
+ unique: unique,
934
+ type: bitmap ? 'bitmap' : undefined
935
+ }));
936
+ }
937
+
938
+ // table_index_clause
939
+ // : tableview_name table_alias? '(' index_expr (ASC | DESC)? (',' index_expr (ASC | DESC)?)* ')' index_properties?
940
+ // ;
941
+ }, {
942
+ key: "visitTable_index_clause",
943
+ value: function visitTable_index_clause(ctx) {
944
+ var _this13 = this;
945
+ var names = ctx.tableview_name().accept(this);
946
+ var columns = ctx.index_expr().map(function (i) {
947
+ return i.accept(_this13);
948
+ });
949
+ return {
950
+ names: names,
951
+ columns: columns
952
+ };
953
+ }
954
+
955
+ // constraint_name
956
+ // : id_expression
957
+ // ;
958
+ }, {
959
+ key: "visitConstraint_name",
960
+ value: function visitConstraint_name(ctx) {
961
+ return (0, _helpers.getOriginalText)(ctx);
962
+ }
963
+ }, {
964
+ key: "visitIndex_name",
965
+ value: function visitIndex_name(ctx) {
966
+ return ctx.identifier().accept(this);
967
+ }
968
+
969
+ // index_expr
970
+ // : column_name
971
+ // | expression
972
+ // ;
973
+ }, {
974
+ key: "visitIndex_expr",
975
+ value: function visitIndex_expr(ctx) {
976
+ if (ctx.expression()) {
977
+ var expression = processIndexExpression(ctx.expression().accept(this));
978
+ return {
979
+ value: expression.value,
980
+ type: expression.type
981
+ };
982
+ }
983
+ var columnName = (0, _lodash.last)(ctx.column_name().accept(this));
984
+ return {
985
+ value: columnName,
986
+ type: _constants.CONSTRAINT_TYPE.COLUMN
987
+ };
988
+ }
989
+
990
+ // insert_statement
991
+ // : INSERT (single_table_insert | <other rules>)
992
+ // ;
993
+ }, {
994
+ key: "visitInsert_statement",
995
+ value: function visitInsert_statement(ctx) {
996
+ if (ctx.single_table_insert()) {
997
+ ctx.single_table_insert().accept(this);
998
+ }
999
+ }
1000
+
1001
+ // single_table_insert
1002
+ // : insert_into_clause (values_clause | <other rules>)
1003
+ // ;
1004
+ }, {
1005
+ key: "visitSingle_table_insert",
1006
+ value: function visitSingle_table_insert(ctx) {
1007
+ var intoClause = ctx.insert_into_clause().accept(this);
1008
+ var valuesClause = ctx.values_clause().accept(this);
1009
+ if (intoClause && valuesClause) {
1010
+ var tableName = intoClause.tableName,
1011
+ schemaName = intoClause.schemaName,
1012
+ columns = intoClause.columns;
1013
+ var values = valuesClause.values;
1014
+ var record = new _AST.TableRecord({
1015
+ schemaName: schemaName,
1016
+ tableName: tableName,
1017
+ columns: columns,
1018
+ values: values
1019
+ });
1020
+ this.data.records.push(record);
1021
+ }
1022
+ }
1023
+
1024
+ // insert_into_clause
1025
+ // : INTO general_table_ref paren_column_list?
1026
+ // ;
1027
+ }, {
1028
+ key: "visitInsert_into_clause",
1029
+ value: function visitInsert_into_clause(ctx) {
1030
+ var names = ctx.general_table_ref().accept(this);
1031
+ var tableName = (0, _lodash.last)(names);
1032
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
1033
+ var columns = ctx.paren_column_list() ? ctx.paren_column_list().accept(this).map(function (c) {
1034
+ return (0, _lodash.last)(c);
1035
+ }) : [];
1036
+ return {
1037
+ tableName: tableName,
1038
+ schemaName: schemaName,
1039
+ columns: columns
1040
+ };
1041
+ }
1042
+ }, {
1043
+ key: "visitGeneral_table_ref",
1044
+ value: function visitGeneral_table_ref(ctx) {
1045
+ return ctx.dml_table_expression_clause().accept(this);
1046
+ }
1047
+ }, {
1048
+ key: "visitDml_table_expression_clause",
1049
+ value: function visitDml_table_expression_clause(ctx) {
1050
+ if (ctx.tableview_name()) {
1051
+ return ctx.tableview_name().accept(this);
1052
+ }
1053
+ return [];
1054
+ }
1055
+ }, {
1056
+ key: "visitParen_column_list",
1057
+ value: function visitParen_column_list(ctx) {
1058
+ return ctx.column_list().accept(this);
1059
+ }
1060
+
1061
+ // values_clause
1062
+ // : VALUES '(' expressions_ ')'
1063
+ // ;
1064
+ }, {
1065
+ key: "visitValues_clause",
1066
+ value: function visitValues_clause(ctx) {
1067
+ var expressions = ctx.expressions_().accept(this);
1068
+ return {
1069
+ values: [expressions.map(function (e) {
1070
+ return {
1071
+ value: e.type !== _constants.CONSTRAINT_TYPE.COLUMN ? e.value : e.rawValue,
1072
+ type: e.type !== _constants.CONSTRAINT_TYPE.COLUMN ? e.type : _constants.DATA_TYPE.EXPRESSION
1073
+ };
1074
+ })]
1075
+ };
1076
+ }
1077
+ }, {
1078
+ key: "visitExpressions_",
1079
+ value: function visitExpressions_(ctx) {
1080
+ var _this14 = this;
1081
+ return ctx.expression().map(function (e) {
1082
+ return e.accept(_this14);
1083
+ });
1084
+ }
1085
+ }, {
1086
+ key: "visitId_expression",
1087
+ value: function visitId_expression(ctx) {
1088
+ return (0, _helpers.getOriginalText)(ctx);
1089
+ }
1090
+
1091
+ // expression
1092
+ // : CHAR_STRING
1093
+ // | TRUE
1094
+ // | FALSE
1095
+ // | NULL_
1096
+ // | APPROXIMATE_NUM_LIT
1097
+ // | UNSIGNED_INTEGER
1098
+ // | column_name
1099
+ // | cursor_expression
1100
+ // | logical_expression
1101
+ // ;
1102
+ }, {
1103
+ key: "visitExpression",
1104
+ value: function visitExpression(ctx) {
1105
+ var value = (0, _helpers.getOriginalText)(ctx);
1106
+ if (ctx.CHAR_STRING()) {
1107
+ return {
1108
+ type: _constants.DATA_TYPE.STRING,
1109
+ value: value.slice(1, -1)
1110
+ };
1111
+ }
1112
+ if (ctx.TRUE()) {
1113
+ return {
1114
+ type: _constants.DATA_TYPE.BOOLEAN,
1115
+ value: true
1116
+ };
1117
+ }
1118
+ if (ctx.FALSE()) {
1119
+ return {
1120
+ type: _constants.DATA_TYPE.BOOLEAN,
1121
+ value: false
1122
+ };
1123
+ }
1124
+ if (ctx.NULL_()) {
1125
+ return {
1126
+ type: _constants.DATA_TYPE.BOOLEAN,
1127
+ value: null
1128
+ };
1129
+ }
1130
+ if (ctx.APPROXIMATE_NUM_LIT() || ctx.UNSIGNED_INTEGER()) {
1131
+ return {
1132
+ type: _constants.DATA_TYPE.NUMBER,
1133
+ value: parseFloat(value)
1134
+ };
1135
+ }
1136
+ if (ctx.column_name()) {
1137
+ return {
1138
+ type: _constants.CONSTRAINT_TYPE.COLUMN,
1139
+ rawValue: value,
1140
+ value: (0, _helpers.getOriginalText)(ctx.column_name())
1141
+ };
1142
+ }
1143
+ return {
1144
+ type: _constants.CONSTRAINT_TYPE.EXPRESSION,
1145
+ value: value
1146
+ };
1147
+ }
1148
+ }, {
1149
+ key: "visitQuoted_string",
1150
+ value: function visitQuoted_string(ctx) {
1151
+ return (0, _helpers.getOriginalText)(ctx).slice(1, -1).replaceAll("''", "'");
1152
+ }
1153
+ }]);
1154
+ }(_OracleSqlParserVisitor["default"]);