@dbml/core 2.5.3 → 2.6.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 (30) hide show
  1. package/README.md +1 -1
  2. package/lib/model_structure/field.js +3 -1
  3. package/lib/parse/ANTLR/ASTGeneration/AST.js +246 -0
  4. package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +40 -0
  5. package/lib/parse/ANTLR/ASTGeneration/PostgresASTGen.js +1126 -0
  6. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +47 -0
  7. package/lib/parse/ANTLR/ASTGeneration/index.js +32 -0
  8. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +43 -0
  9. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +37 -0
  10. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +1126 -0
  11. package/lib/parse/ANTLR/README.md +32 -0
  12. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +3044 -0
  13. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +2074 -0
  14. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +882 -0
  15. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +1314 -0
  16. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexerBase.js +42 -0
  17. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +5506 -0
  18. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +2182 -0
  19. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +3 -0
  20. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -0
  21. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserBase.js +36 -0
  22. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +5767 -0
  23. package/lib/parse/ANTLR/parsers/postgresql/README.md +10 -0
  24. package/lib/parse/Parser.js +9 -0
  25. package/lib/parse/dbml/parser.pegjs +2 -2
  26. package/lib/parse/dbmlParser.js +66 -103
  27. package/lib/parse/mssql/constraint_definition/index.js +3 -3
  28. package/package.json +6 -3
  29. package/types/import/index.d.ts +1 -1
  30. package/types/parse/Parser.d.ts +1 -0
@@ -0,0 +1,1126 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _lodash = require("lodash");
9
+ var _PostgreSQLParserVisitor = _interopRequireDefault(require("../parsers/postgresql/PostgreSQLParserVisitor"));
10
+ var _AST = require("./AST");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
+ 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; }
13
+ 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; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
16
+ 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."); }
17
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
20
+ 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."); }
21
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
23
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
24
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
26
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
27
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
28
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
29
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
30
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
31
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
33
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
36
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /* eslint-disable class-methods-use-this */
37
+ var COMMAND_KIND = {
38
+ REF: 'ref'
39
+ };
40
+ var TABLE_CONSTRAINT_KIND = {
41
+ FIELD: 'field',
42
+ INDEX: 'index',
43
+ FK: 'fk',
44
+ UNIQUE: 'unique'
45
+ };
46
+ var COMMENT_OBJECT_TYPE = {
47
+ TABLE: 'table'
48
+ };
49
+
50
+ // legacy - for compatibility with model_structure
51
+ var CONSTRAINT_TYPE = {
52
+ COLUMN: 'column',
53
+ STRING: 'string',
54
+ EXPRESSION: 'expression'
55
+ };
56
+ var findTable = function findTable(tables, schemaName, tableName) {
57
+ var realSchemaName = schemaName || 'public';
58
+ var table = tables.find(function (table) {
59
+ var targetSchemaName = table.schemaName || 'public';
60
+ return targetSchemaName === realSchemaName && table.name === tableName;
61
+ });
62
+ return table;
63
+ };
64
+ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
65
+ _inherits(PostgresASTGen, _PostgreSQLParserVisi);
66
+ var _super = _createSuper(PostgresASTGen);
67
+ function PostgresASTGen() {
68
+ var _this;
69
+ _classCallCheck(this, PostgresASTGen);
70
+ _this = _super.call(this);
71
+ _this.data = {
72
+ schemas: [],
73
+ tables: [],
74
+ refs: [],
75
+ enums: [],
76
+ tableGroups: [],
77
+ aliases: [],
78
+ project: {}
79
+ };
80
+ return _this;
81
+ }
82
+
83
+ // stmtblock EOF
84
+ _createClass(PostgresASTGen, [{
85
+ key: "visitRoot",
86
+ value: function visitRoot(ctx) {
87
+ ctx.stmtblock().accept(this);
88
+ return this.data;
89
+ }
90
+
91
+ // stmtmulti
92
+ }, {
93
+ key: "visitStmtblock",
94
+ value: function visitStmtblock(ctx) {
95
+ ctx.stmtmulti().accept(this);
96
+ }
97
+
98
+ // (stmt SEMI?)*
99
+ }, {
100
+ key: "visitStmtmulti",
101
+ value: function visitStmtmulti(ctx) {
102
+ var _this2 = this;
103
+ ctx.stmt().map(function (stmt) {
104
+ return stmt.accept(_this2);
105
+ });
106
+ }
107
+
108
+ // check PostgresSQLParser.g4 line 31
109
+ }, {
110
+ key: "visitStmt",
111
+ value: function visitStmt(ctx) {
112
+ if (ctx.createstmt()) {
113
+ var table = ctx.createstmt().accept(this);
114
+ return this.data.tables.push(table);
115
+ }
116
+ if (ctx.indexstmt()) {
117
+ /** @type {Index} */
118
+ var indexStmt = ctx.indexstmt().accept(this);
119
+ var _indexStmt$pathName = indexStmt.pathName,
120
+ tableName = _indexStmt$pathName.tableName,
121
+ schemaName = _indexStmt$pathName.schemaName;
122
+ var _table = findTable(this.data.tables, schemaName, tableName);
123
+ if (!_table) return;
124
+ return _table.indexes.push(indexStmt.index);
125
+ }
126
+ if (ctx.altertablestmt()) {
127
+ ctx.altertablestmt().accept(this);
128
+ return;
129
+ }
130
+ if (ctx.commentstmt()) {
131
+ ctx.commentstmt().accept(this);
132
+ return;
133
+ }
134
+ if (ctx.definestmt()) {
135
+ ctx.definestmt().accept(this);
136
+ return;
137
+ }
138
+ }
139
+
140
+ /*
141
+ CREATE opttemp TABLE (IF_P NOT EXISTS)? qualified_name (
142
+ OPEN_PAREN opttableelementlist CLOSE_PAREN optinherit optpartitionspec
143
+ table_access_method_clause optwith oncommitoption opttablespace
144
+ | OF any_name opttypedtableelementlist optpartitionspec table_access_method_clause
145
+ optwith oncommitoption opttablespace | PARTITION OF qualified_name opttypedtableelementlist
146
+ partitionboundspec optpartitionspec table_access_method_clause optwith oncommitoption opttablespace)
147
+ */
148
+ }, {
149
+ key: "visitCreatestmt",
150
+ value: function visitCreatestmt(ctx) {
151
+ var _this$data$refs, _this$data$refs2;
152
+ var names = ctx.qualified_name(0).accept(this);
153
+ var tableName = (0, _lodash.last)(names);
154
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
155
+ if (!ctx.opttableelementlist()) return;
156
+ var tableElements = ctx.opttableelementlist().accept(this).filter(function (e) {
157
+ return e;
158
+ });
159
+ var _tableElements$reduce = tableElements.reduce(function (acc, ele) {
160
+ if (ele.kind === TABLE_CONSTRAINT_KIND.FIELD) acc[0].push(ele.value);else if (ele.kind === TABLE_CONSTRAINT_KIND.INDEX) acc[1].push(ele.value);else if (ele.kind === TABLE_CONSTRAINT_KIND.FK) acc[2].push(ele.value);else if (ele.kind === TABLE_CONSTRAINT_KIND.UNIQUE) acc[1].push(ele.value);
161
+ return acc;
162
+ }, [[], [], []]),
163
+ _tableElements$reduce2 = _slicedToArray(_tableElements$reduce, 3),
164
+ fieldsData = _tableElements$reduce2[0],
165
+ indexes = _tableElements$reduce2[1],
166
+ tableRefs = _tableElements$reduce2[2];
167
+ (_this$data$refs = this.data.refs).push.apply(_this$data$refs, _toConsumableArray((0, _lodash.flatten)(fieldsData.map(function (fieldData) {
168
+ return fieldData.inline_refs.map(function (inlineRef) {
169
+ inlineRef.endpoints[0].tableName = tableName;
170
+ inlineRef.endpoints[0].schemaName = schemaName;
171
+ inlineRef.endpoints[0].fieldNames = [fieldData.field.name];
172
+ return inlineRef;
173
+ });
174
+ }))));
175
+ (_this$data$refs2 = this.data.refs).push.apply(_this$data$refs2, _toConsumableArray(tableRefs.map(function (tableRef) {
176
+ tableRef.endpoints[0].tableName = tableName;
177
+ tableRef.endpoints[0].schemaName = schemaName;
178
+ return tableRef;
179
+ })));
180
+ return new _AST.Table({
181
+ name: tableName,
182
+ schemaName: schemaName,
183
+ fields: fieldsData.map(function (fd) {
184
+ return fd.field;
185
+ }),
186
+ indexes: indexes
187
+ });
188
+ }
189
+
190
+ // tableelementlist
191
+ }, {
192
+ key: "visitOpttableelementlist",
193
+ value: function visitOpttableelementlist(ctx) {
194
+ if (!ctx.tableelementlist()) return [];
195
+ return ctx.tableelementlist().accept(this);
196
+ }
197
+
198
+ // tableelement (COMMA tableelement)*
199
+ }, {
200
+ key: "visitTableelementlist",
201
+ value: function visitTableelementlist(ctx) {
202
+ var _this3 = this;
203
+ return ctx.tableelement().map(function (element) {
204
+ return element.accept(_this3);
205
+ });
206
+ }
207
+
208
+ // tableconstraint | tablelikeclause | columnDef
209
+ }, {
210
+ key: "visitTableelement",
211
+ value: function visitTableelement(ctx) {
212
+ if (ctx.columnDef()) return ctx.columnDef().accept(this);
213
+ if (ctx.tableconstraint()) return ctx.tableconstraint().accept(this);
214
+ }
215
+
216
+ // CONSTRAINT name constraintelem | constraintelem
217
+ }, {
218
+ key: "visitTableconstraint",
219
+ value: function visitTableconstraint(ctx) {
220
+ var _ctx$name;
221
+ var constraintName = (_ctx$name = ctx.name()) === null || _ctx$name === void 0 ? void 0 : _ctx$name.accept(this);
222
+ var constraint = ctx.constraintelem().accept(this);
223
+ if (!constraint) return;
224
+ constraint.value.name = constraintName;
225
+ return constraint;
226
+ }
227
+
228
+ /*
229
+ CHECK OPEN_PAREN a_expr CLOSE_PAREN constraintattributespec
230
+ | UNIQUE (OPEN_PAREN columnlist CLOSE_PAREN opt_c_include opt_definition optconstablespace constraintattributespec | existingindex constraintattributespec)
231
+ | PRIMARY KEY (OPEN_PAREN columnlist CLOSE_PAREN opt_c_include opt_definition optconstablespace constraintattributespec | existingindex constraintattributespec)
232
+ | EXCLUDE access_method_clause OPEN_PAREN exclusionconstraintlist CLOSE_PAREN opt_c_include opt_definition optconstablespace exclusionwhereclause constraintattributespec
233
+ | FOREIGN KEY OPEN_PAREN columnlist CLOSE_PAREN REFERENCES qualified_name opt_column_list key_match key_actions constraintattributespec
234
+ */
235
+ }, {
236
+ key: "visitConstraintelem",
237
+ value: function visitConstraintelem(ctx) {
238
+ if (ctx.PRIMARY()) {
239
+ return {
240
+ kind: TABLE_CONSTRAINT_KIND.INDEX,
241
+ value: new _AST.Index({
242
+ pk: true,
243
+ columns: ctx.columnlist().accept(this)
244
+ })
245
+ // value: {
246
+ // type: 'PrimaryKey',
247
+ // columns:
248
+ // },
249
+ };
250
+ }
251
+
252
+ if (ctx.FOREIGN()) {
253
+ var _ctx$opt_column_list$;
254
+ var names = ctx.qualified_name().accept(this);
255
+ var refTableName = (0, _lodash.last)(names);
256
+ var refSchemaName = names.length > 1 ? names[names.length - 2] : undefined;
257
+ var firstFieldNames = ctx.columnlist().accept(this).map(function (c) {
258
+ return c.value;
259
+ });
260
+ var secondFieldNames = (_ctx$opt_column_list$ = ctx.opt_column_list().accept(this)) === null || _ctx$opt_column_list$ === void 0 ? void 0 : _ctx$opt_column_list$.map(function (c) {
261
+ return c.value;
262
+ });
263
+ var actions = ctx.key_actions().accept(this);
264
+ return {
265
+ kind: TABLE_CONSTRAINT_KIND.FK,
266
+ value: {
267
+ endpoints: [{
268
+ tableName: null,
269
+ schemaName: null,
270
+ fieldNames: firstFieldNames,
271
+ relation: '*'
272
+ }, {
273
+ tableName: refTableName,
274
+ schemaName: refSchemaName,
275
+ fieldNames: secondFieldNames,
276
+ relation: '1'
277
+ }],
278
+ onDelete: actions.onDelete,
279
+ onUpdate: actions.onUpdate
280
+ }
281
+ };
282
+ }
283
+ if (ctx.UNIQUE()) {
284
+ return {
285
+ kind: TABLE_CONSTRAINT_KIND.UNIQUE,
286
+ value: new _AST.Index({
287
+ unique: true,
288
+ columns: ctx.columnlist().accept(this)
289
+ })
290
+ };
291
+ }
292
+ }
293
+
294
+ // OPEN_PAREN columnlist CLOSE_PAREN |
295
+ }, {
296
+ key: "visitOpt_column_list",
297
+ value: function visitOpt_column_list(ctx) {
298
+ var _ctx$columnlist;
299
+ return (_ctx$columnlist = ctx.columnlist()) === null || _ctx$columnlist === void 0 ? void 0 : _ctx$columnlist.accept(this);
300
+ }
301
+
302
+ // columnElem (COMMA columnElem)*
303
+ }, {
304
+ key: "visitColumnlist",
305
+ value: function visitColumnlist(ctx) {
306
+ var _this4 = this;
307
+ return ctx.columnElem().map(function (c) {
308
+ return c.accept(_this4);
309
+ });
310
+ }
311
+
312
+ // colid
313
+ }, {
314
+ key: "visitColumnElem",
315
+ value: function visitColumnElem(ctx) {
316
+ return {
317
+ value: ctx.colid().accept(this),
318
+ type: CONSTRAINT_TYPE.COLUMN
319
+ };
320
+ }
321
+
322
+ // colid typename create_generic_options colquallist
323
+ }, {
324
+ key: "visitColumnDef",
325
+ value: function visitColumnDef(ctx) {
326
+ var name = ctx.colid().accept(this);
327
+ var type = ctx.typename().accept(this);
328
+ var contraints = ctx.colquallist().accept(this);
329
+ var serialIncrementType = new Set(['serial', 'smallserial', 'bigserial']);
330
+ var columnTypeName = type.type_name.toLowerCase();
331
+ if (serialIncrementType.has(columnTypeName)) contraints.increment = true;
332
+ return {
333
+ kind: TABLE_CONSTRAINT_KIND.FIELD,
334
+ value: {
335
+ field: new _AST.Field(_objectSpread({
336
+ name: name,
337
+ type: type
338
+ }, contraints)),
339
+ inline_refs: contraints.inline_refs
340
+ }
341
+ };
342
+ }
343
+
344
+ // colconstraint*
345
+ }, {
346
+ key: "visitColquallist",
347
+ value: function visitColquallist(ctx) {
348
+ var _this5 = this;
349
+ var r = {
350
+ inline_refs: []
351
+ };
352
+ ctx.colconstraint().forEach(function (c) {
353
+ var constraint = c.accept(_this5);
354
+ if (!constraint) return;
355
+ if (constraint.kind === 'inline_ref') {
356
+ r.inline_refs.push(constraint.value);
357
+ return;
358
+ }
359
+ r[constraint.kind] = constraint.value;
360
+ });
361
+ return r;
362
+ }
363
+
364
+ /*
365
+ CONSTRAINT name colconstraintelem
366
+ | colconstraintelem
367
+ | constraintattr
368
+ | COLLATE any_name
369
+ */
370
+ }, {
371
+ key: "visitColconstraint",
372
+ value: function visitColconstraint(ctx) {
373
+ if (ctx.colconstraintelem()) {
374
+ return ctx.colconstraintelem().accept(this);
375
+ }
376
+ }
377
+
378
+ /*
379
+ NOT NULL_P
380
+ | NULL_P
381
+ | UNIQUE opt_definition optconstablespace
382
+ | PRIMARY KEY opt_definition optconstablespace
383
+ | CHECK OPEN_PAREN a_expr CLOSE_PAREN opt_no_inherit
384
+ | DEFAULT b_expr
385
+ | GENERATED generated_when AS (IDENTITY_P optparenthesizedseqoptlist | OPEN_PAREN a_expr CLOSE_PAREN STORED)
386
+ | REFERENCES qualified_name opt_column_list key_match key_actions
387
+ */
388
+ }, {
389
+ key: "visitColconstraintelem",
390
+ value: function visitColconstraintelem(ctx) {
391
+ if (ctx.NULL_P()) {
392
+ var not_null = false;
393
+ if (ctx.NOT()) not_null = true;
394
+ return {
395
+ kind: 'not_null',
396
+ value: not_null
397
+ };
398
+ }
399
+ if (ctx.UNIQUE()) return {
400
+ kind: 'unique',
401
+ value: true
402
+ };
403
+ if (ctx.PRIMARY()) return {
404
+ kind: 'pk',
405
+ value: true
406
+ };
407
+ if (ctx.DEFAULT()) return {
408
+ kind: 'dbdefault',
409
+ value: ctx.b_expr().accept(this)
410
+ };
411
+ if (ctx.IDENTITY_P()) return {
412
+ kind: 'increment',
413
+ value: true
414
+ };
415
+ if (ctx.REFERENCES()) {
416
+ var _ctx$opt_column_list$2;
417
+ var names = ctx.qualified_name().accept(this);
418
+ var refTableName = (0, _lodash.last)(names);
419
+ var refSchemaName = names.length > 1 ? names[names.length - 2] : undefined;
420
+ var secondFieldNames = (_ctx$opt_column_list$2 = ctx.opt_column_list().accept(this)) === null || _ctx$opt_column_list$2 === void 0 ? void 0 : _ctx$opt_column_list$2.map(function (c) {
421
+ return c.value;
422
+ });
423
+ var actions = ctx.key_actions().accept(this);
424
+ return {
425
+ kind: 'inline_ref',
426
+ value: {
427
+ endpoints: [{
428
+ tableName: null,
429
+ schemaName: null,
430
+ fieldNames: null,
431
+ relation: '*'
432
+ }, {
433
+ tableName: refTableName,
434
+ schemaName: refSchemaName,
435
+ fieldNames: secondFieldNames,
436
+ relation: '1'
437
+ }],
438
+ onDelete: actions.onDelete,
439
+ onUpdate: actions.onUpdate
440
+ }
441
+ };
442
+ }
443
+ }
444
+
445
+ // check PostgresSQLParser.g4 line 3619
446
+ }, {
447
+ key: "visitB_expr",
448
+ value: function visitB_expr(ctx) {
449
+ if (ctx.c_expr()) return ctx.c_expr().accept(this);
450
+ return {
451
+ value: ctx.getText(),
452
+ type: 'expression'
453
+ };
454
+ }
455
+
456
+ // check PostgresSQLParser.g4 line 3640
457
+ }, {
458
+ key: "visitC_expr_expr",
459
+ value: function visitC_expr_expr(ctx) {
460
+ if (ctx.aexprconst()) return ctx.aexprconst().accept(this);
461
+ if (ctx.a_expr()) return {
462
+ value: ctx.a_expr().getText(),
463
+ type: 'expression'
464
+ };
465
+ return {
466
+ value: ctx.getText(),
467
+ type: 'expression'
468
+ };
469
+ }
470
+ }, {
471
+ key: "visitC_expr_exists",
472
+ value: function visitC_expr_exists(ctx) {
473
+ return {
474
+ value: ctx.getText(),
475
+ type: 'expression'
476
+ };
477
+ }
478
+ }, {
479
+ key: "visitC_expr_case",
480
+ value: function visitC_expr_case(ctx) {
481
+ return {
482
+ value: ctx.getText(),
483
+ type: 'expression'
484
+ };
485
+ }
486
+
487
+ // iconst | fconst | sconst | bconst | xconst | func_name (sconst | OPEN_PAREN func_arg_list opt_sort_clause CLOSE_PAREN sconst) | consttypename sconst | constinterval (sconst opt_interval | OPEN_PAREN iconst CLOSE_PAREN sconst) | TRUE_P | FALSE_P | NULL_P
488
+ }, {
489
+ key: "visitAexprconst",
490
+ value: function visitAexprconst(ctx) {
491
+ if (ctx.sconst() && ctx.getChildCount() === 1) return {
492
+ value: ctx.sconst().accept(this),
493
+ type: 'string'
494
+ };
495
+ if (ctx.TRUE_P() || ctx.FALSE_P() || ctx.NULL_P()) return {
496
+ value: ctx.getText(),
497
+ type: 'boolean'
498
+ };
499
+ if (ctx.iconst() || ctx.fconst) return {
500
+ value: ctx.getText(),
501
+ type: 'number'
502
+ };
503
+ return {
504
+ value: ctx.getText(),
505
+ type: 'expression'
506
+ };
507
+ }
508
+
509
+ // key_update | key_delete | key_update key_delete | key_delete key_update |
510
+ }, {
511
+ key: "visitKey_actions",
512
+ value: function visitKey_actions(ctx) {
513
+ var onDelete = null,
514
+ onUpdate = null;
515
+ if (ctx.key_update()) onUpdate = ctx.key_update().accept(this);
516
+ if (ctx.key_delete()) onDelete = ctx.key_delete().accept(this);
517
+ return {
518
+ onDelete: onDelete,
519
+ onUpdate: onUpdate
520
+ };
521
+ }
522
+
523
+ // ON UPDATE key_action
524
+ }, {
525
+ key: "visitKey_update",
526
+ value: function visitKey_update(ctx) {
527
+ return ctx.key_action().accept(this);
528
+ }
529
+
530
+ // ON DELETE_P key_action
531
+ }, {
532
+ key: "visitKey_delete",
533
+ value: function visitKey_delete(ctx) {
534
+ return ctx.key_action().accept(this);
535
+ }
536
+
537
+ // NO ACTION | RESTRICT | CASCADE | SET (NULL_P | DEFAULT)
538
+ }, {
539
+ key: "visitKey_action",
540
+ value: function visitKey_action(ctx) {
541
+ // Generate n element integer array [0, 1, ..., n-1]
542
+ var childIndices = _toConsumableArray(Array(ctx.getChildCount()).keys());
543
+ var text = childIndices.reduce(function (acc, i) {
544
+ acc += "".concat(ctx.getChild(i).getText(), " ");
545
+ return acc;
546
+ }, '');
547
+ return text.slice(0, text.length - 1); // remove the last whitespace
548
+ }
549
+
550
+ // colid indirection?
551
+ }, {
552
+ key: "visitQualified_name",
553
+ value: function visitQualified_name(ctx) {
554
+ var r = [ctx.colid().accept(this)];
555
+ if (ctx.indirection()) {
556
+ r.push.apply(r, _toConsumableArray(ctx.indirection().accept(this)));
557
+ }
558
+ return r;
559
+ }
560
+
561
+ /*
562
+ identifier
563
+ | unreserved_keyword
564
+ | col_name_keyword
565
+ | plsql_unreserved_keyword
566
+ | LEFT
567
+ | RIGHT
568
+ */
569
+ }, {
570
+ key: "visitColid",
571
+ value: function visitColid(ctx) {
572
+ return ctx.getChild(0).accept(this);
573
+ }
574
+
575
+ // check PostgresSQLParser.g4 line 4187
576
+ }, {
577
+ key: "visitUnreserved_keyword",
578
+ value: function visitUnreserved_keyword(ctx) {
579
+ return ctx.getChild(0).getText();
580
+ }
581
+ }, {
582
+ key: "visitIdentifier",
583
+ value:
584
+ /*
585
+ Identifier opt_uescape
586
+ | QuotedIdentifier
587
+ | UnicodeQuotedIdentifier
588
+ | plsqlvariablename
589
+ | plsqlidentifier
590
+ | plsql_unreserved_keyword
591
+ */
592
+ function visitIdentifier(ctx) {
593
+ if (ctx.Identifier()) {
594
+ return ctx.Identifier().getText();
595
+ }
596
+ if (ctx.QuotedIdentifier()) {
597
+ var qId = ctx.QuotedIdentifier().getText();
598
+ return qId.slice(1, qId.length - 1);
599
+ }
600
+ if (ctx.UnicodeQuotedIdentifier()) {
601
+ var _qId = ctx.UnicodeQuotedIdentifier().getText();
602
+ return _qId.slice(1, _qId.length - 1);
603
+ }
604
+ if (ctx.plsql_unreserved_keyword()) {
605
+ return ctx.plsql_unreserved_keyword().accept(this);
606
+ }
607
+ return ctx.getChild(0).getText();
608
+ }
609
+ }, {
610
+ key: "visitCol_name_keyword",
611
+ value: function visitCol_name_keyword(ctx) {
612
+ return ctx.getChild(0).getText();
613
+ }
614
+ }, {
615
+ key: "visitPlsql_unreserved_keyword",
616
+ value: function visitPlsql_unreserved_keyword(ctx) {
617
+ return ctx.getChild(0).getText();
618
+ }
619
+
620
+ // indirection_el+
621
+ }, {
622
+ key: "visitIndirection",
623
+ value: function visitIndirection(ctx) {
624
+ var _this6 = this;
625
+ return ctx.indirection_el().map(function (i) {
626
+ return i.accept(_this6);
627
+ });
628
+ }
629
+
630
+ // DOT (attr_name | STAR)
631
+ // | OPEN_BRACKET (a_expr | opt_slice_bound COLON opt_slice_bound) CLOSE_BRACKET
632
+ }, {
633
+ key: "visitIndirection_el",
634
+ value: function visitIndirection_el(ctx) {
635
+ if (ctx.attr_name()) return ctx.attr_name().accept(this);
636
+ }
637
+
638
+ // collabel
639
+ }, {
640
+ key: "visitAttr_name",
641
+ value: function visitAttr_name(ctx) {
642
+ return ctx.collabel().accept(this);
643
+ }
644
+
645
+ /*
646
+ identifier
647
+ | plsql_unreserved_keyword
648
+ | unreserved_keyword
649
+ | col_name_keyword
650
+ | type_func_name_keyword
651
+ | reserved_keyword
652
+ */
653
+ }, {
654
+ key: "visitCollabel",
655
+ value: function visitCollabel(ctx) {
656
+ return ctx.getChild(0).accept(this);
657
+ }
658
+
659
+ // check PostgresSQLParser.g4 line 4567
660
+ }, {
661
+ key: "visitReserved_keyword",
662
+ value: function visitReserved_keyword(ctx) {
663
+ return ctx.getText();
664
+ }
665
+
666
+ // SETOF? simpletypename (opt_array_bounds | ARRAY (OPEN_BRACKET iconst CLOSE_BRACKET)?)
667
+ // | qualified_name PERCENT (ROWTYPE | TYPE_P)
668
+ }, {
669
+ key: "visitTypename",
670
+ value: function visitTypename(ctx) {
671
+ if (ctx.simpletypename()) {
672
+ var arrayExtension = '';
673
+ var type = ctx.simpletypename().accept(this);
674
+ if (ctx.opt_array_bounds()) arrayExtension = ctx.opt_array_bounds().accept(this);
675
+ if (ctx.ARRAY()) arrayExtension = "[".concat(ctx.iconst() ? ctx.iconst().accept(this) : '', "]");
676
+ return {
677
+ type_name: type.type + arrayExtension,
678
+ schemaName: type.schemaName
679
+ };
680
+ }
681
+ }
682
+
683
+ /*
684
+ generictype
685
+ | numeric
686
+ | bit
687
+ | character
688
+ | constdatetime
689
+ | constinterval (opt_interval | OPEN_PAREN iconst CLOSE_PAREN)
690
+ */
691
+ }, {
692
+ key: "visitSimpletypename",
693
+ value: function visitSimpletypename(ctx) {
694
+ if (ctx.generictype()) return ctx.generictype().accept(this);
695
+ if (ctx.character()) return {
696
+ type: ctx.character().accept(this),
697
+ schemaName: null
698
+ };
699
+ if (ctx.numeric()) return {
700
+ type: ctx.numeric().accept(this),
701
+ schemaName: null
702
+ };
703
+ if (ctx.constdatetime()) return {
704
+ type: ctx.constdatetime().accept(this),
705
+ schemaName: null
706
+ };
707
+ return {
708
+ type: ctx.getText(),
709
+ schemaName: null
710
+ };
711
+ }
712
+
713
+ // (TIMESTAMP | TIME) (OPEN_PAREN iconst CLOSE_PAREN)? opt_timezone
714
+ }, {
715
+ key: "visitConstdatetime",
716
+ value: function visitConstdatetime(ctx) {
717
+ return "".concat(ctx.getChild(0).getText()).concat(ctx.iconst() ? "(".concat(ctx.iconst().accept(this), ")") : '');
718
+ }
719
+
720
+ // INT_P | INTEGER | SMALLINT | BIGINT | REAL | FLOAT_P opt_float | DOUBLE_P PRECISION | DECIMAL_P opt_type_modifiers | DEC opt_type_modifiers | NUMERIC opt_type_modifiers | BOOLEAN_P
721
+ }, {
722
+ key: "visitNumeric",
723
+ value: function visitNumeric(ctx) {
724
+ return ctx.getText();
725
+ }
726
+
727
+ // (builtin_function_name | type_function_name | LEFT | RIGHT) attrs? opt_type_modifiers
728
+ }, {
729
+ key: "visitGenerictype",
730
+ value: function visitGenerictype(ctx) {
731
+ if (ctx.attrs()) {
732
+ var names = [ctx.getChild(0).getText()].concat(_toConsumableArray(ctx.attrs().accept(this)));
733
+ var enumName = (0, _lodash.last)(names);
734
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
735
+ return {
736
+ type: enumName,
737
+ schemaName: schemaName
738
+ };
739
+ }
740
+ var type = '';
741
+ if (ctx.type_function_name()) type = ctx.type_function_name().accept(this);else type = ctx.getText();
742
+ return {
743
+ type: type + ctx.opt_type_modifiers().getText(),
744
+ schemaName: null
745
+ };
746
+ }
747
+
748
+ // character_c (OPEN_PAREN iconst CLOSE_PAREN)?
749
+ }, {
750
+ key: "visitCharacter",
751
+ value: function visitCharacter(ctx) {
752
+ var r = ctx.character_c().accept(this);
753
+ if (ctx.getChildCount() > 1) {
754
+ r += "(".concat(ctx.iconst().accept(this), ")");
755
+ }
756
+ return r;
757
+ }
758
+
759
+ // (CHARACTER | CHAR_P | NCHAR) opt_varying
760
+ // | VARCHAR
761
+ // | NATIONAL (CHARACTER | CHAR_P) opt_varying
762
+ }, {
763
+ key: "visitCharacter_c",
764
+ value: function visitCharacter_c(ctx) {
765
+ // Generate n element integer array [0, 1, ..., n-1]
766
+ var childIndices = _toConsumableArray(Array(ctx.getChildCount()).keys());
767
+ var text = childIndices.reduce(function (acc, i) {
768
+ acc += "".concat(ctx.getChild(i).getText(), " ");
769
+ return acc;
770
+ }, '');
771
+ return text.slice(0, text.length - 1); // remove the last whitespace
772
+ }
773
+
774
+ // identifier | unreserved_keyword | plsql_unreserved_keyword | type_func_name_keyword
775
+ }, {
776
+ key: "visitType_function_name",
777
+ value: function visitType_function_name(ctx) {
778
+ return ctx.getChild(0).accept(this);
779
+ }
780
+ }, {
781
+ key: "visitType_func_name_keyword",
782
+ value: function visitType_func_name_keyword(ctx) {
783
+ return ctx.getText();
784
+ }
785
+
786
+ // (OPEN_BRACKET iconst? CLOSE_BRACKET)*
787
+ }, {
788
+ key: "visitOpt_array_bounds",
789
+ value: function visitOpt_array_bounds(ctx) {
790
+ return ctx.getText();
791
+ }
792
+
793
+ // Integral
794
+ }, {
795
+ key: "visitIconst",
796
+ value: function visitIconst(ctx) {
797
+ return ctx.Integral().getText();
798
+ }
799
+
800
+ // CREATE opt_unique INDEX opt_concurrently opt_index_name ON relation_expr access_method_clause OPEN_PAREN index_params CLOSE_PAREN opt_include opt_reloptions opttablespace where_clause
801
+ // | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name ON relation_expr access_method_clause OPEN_PAREN index_params CLOSE_PAREN opt_include opt_reloptions opttablespace where_clause
802
+ }, {
803
+ key: "visitIndexstmt",
804
+ value: function visitIndexstmt(ctx) {
805
+ var names = ctx.relation_expr().accept(this);
806
+ var tableName = (0, _lodash.last)(names);
807
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
808
+ if (ctx.opt_index_name()) {
809
+ var r = {
810
+ pathName: {
811
+ tableName: tableName,
812
+ schemaName: schemaName
813
+ },
814
+ index: new _AST.Index({
815
+ name: ctx.opt_index_name().accept(this),
816
+ unique: ctx.opt_unique().accept(this),
817
+ type: ctx.access_method_clause().accept(this),
818
+ columns: ctx.index_params().accept(this)
819
+ })
820
+ };
821
+ return r;
822
+ }
823
+ }
824
+
825
+ // name |
826
+ }, {
827
+ key: "visitOpt_index_name",
828
+ value: function visitOpt_index_name(ctx) {
829
+ var _ctx$name2;
830
+ return (_ctx$name2 = ctx.name()) === null || _ctx$name2 === void 0 ? void 0 : _ctx$name2.accept(this);
831
+ }
832
+
833
+ // colid
834
+ }, {
835
+ key: "visitName",
836
+ value: function visitName(ctx) {
837
+ return ctx.colid().accept(this);
838
+ }
839
+
840
+ // USING name |
841
+ }, {
842
+ key: "visitAccess_method_clause",
843
+ value: function visitAccess_method_clause(ctx) {
844
+ if (ctx.name()) return ctx.name().accept(this);
845
+ }
846
+
847
+ // qualified_name STAR?
848
+ // | ONLY (qualified_name | OPEN_PAREN qualified_name CLOSE_PAREN)
849
+ }, {
850
+ key: "visitRelation_expr",
851
+ value: function visitRelation_expr(ctx) {
852
+ return ctx.qualified_name().accept(this);
853
+ }
854
+
855
+ // index_elem (COMMA index_elem)*
856
+ }, {
857
+ key: "visitIndex_params",
858
+ value: function visitIndex_params(ctx) {
859
+ var _this7 = this;
860
+ return ctx.index_elem().map(function (i) {
861
+ return i.accept(_this7);
862
+ }).filter(function (col) {
863
+ return !!col;
864
+ });
865
+ }
866
+
867
+ /*
868
+ colid index_elem_options
869
+ | func_expr_windowless index_elem_options
870
+ | OPEN_PAREN a_expr CLOSE_PAREN index_elem_options
871
+ */
872
+ }, {
873
+ key: "visitIndex_elem",
874
+ value: function visitIndex_elem(ctx) {
875
+ if (ctx.colid()) {
876
+ return {
877
+ value: ctx.colid().accept(this),
878
+ type: CONSTRAINT_TYPE.STRING
879
+ };
880
+ }
881
+ return {
882
+ value: ctx.getText(),
883
+ type: CONSTRAINT_TYPE.EXPRESSION
884
+ };
885
+ }
886
+
887
+ // UNIQUE |
888
+ }, {
889
+ key: "visitOpt_unique",
890
+ value: function visitOpt_unique(ctx) {
891
+ return !!ctx.UNIQUE();
892
+ }
893
+
894
+ /*
895
+ ALTER TABLE (IF_P EXISTS)? relation_expr (alter_table_cmds | partition_cmd)
896
+ | ALTER TABLE ALL IN_P TABLESPACE name (OWNED BY role_list)? SET TABLESPACE name opt_nowait
897
+ | ALTER INDEX (IF_P EXISTS)? qualified_name (alter_table_cmds | index_partition_cmd)
898
+ | ALTER INDEX ALL IN_P TABLESPACE name (OWNED BY role_list)? SET TABLESPACE name opt_nowait
899
+ | ALTER SEQUENCE (IF_P EXISTS)? qualified_name alter_table_cmds
900
+ | ALTER VIEW (IF_P EXISTS)? qualified_name alter_table_cmds
901
+ | ALTER MATERIALIZED VIEW (IF_P EXISTS)? qualified_name alter_table_cmds
902
+ | ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name (OWNED BY role_list)? SET TABLESPACE name opt_nowait
903
+ | ALTER FOREIGN TABLE (IF_P EXISTS)? relation_expr alter_table_cmds
904
+ */
905
+ }, {
906
+ key: "visitAltertablestmt",
907
+ value: function visitAltertablestmt(ctx) {
908
+ var _this8 = this;
909
+ if (ctx.TABLE() && ctx.relation_expr() && ctx.alter_table_cmds()) {
910
+ var names = ctx.relation_expr().accept(this);
911
+ var tableName = (0, _lodash.last)(names);
912
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
913
+ var cmds = ctx.alter_table_cmds().accept(this);
914
+ return cmds.map(function (cmd) {
915
+ if (!cmd) return;
916
+ var kind = null;
917
+ switch (cmd.kind) {
918
+ case TABLE_CONSTRAINT_KIND.FK:
919
+ kind = COMMAND_KIND.REF;
920
+ cmd.value.endpoints[0].tableName = tableName;
921
+ cmd.value.endpoints[0].schemaName = schemaName;
922
+ _this8.data.refs.push(cmd.value);
923
+ break;
924
+ default:
925
+ break;
926
+ }
927
+ return {
928
+ kind: kind,
929
+ value: cmd.value
930
+ };
931
+ }).filter(function (c) {
932
+ return c;
933
+ });
934
+ }
935
+ }
936
+
937
+ // alter_table_cmd (COMMA alter_table_cmd)*
938
+ }, {
939
+ key: "visitAlter_table_cmds",
940
+ value: function visitAlter_table_cmds(ctx) {
941
+ var _this9 = this;
942
+ return ctx.alter_table_cmd().map(function (a) {
943
+ return a.accept(_this9);
944
+ });
945
+ }
946
+
947
+ // check PostgresSQLParser.g4 line 410
948
+ }, {
949
+ key: "visitAlter_table_cmd",
950
+ value: function visitAlter_table_cmd(ctx) {
951
+ if (ctx.tableconstraint()) {
952
+ var constraint = ctx.tableconstraint().accept(this);
953
+ return constraint;
954
+ }
955
+ }
956
+
957
+ /*
958
+ COMMENT ON object_type_any_name any_name IS comment_text
959
+ | COMMENT ON COLUMN any_name IS comment_text
960
+ | COMMENT ON object_type_name name IS comment_text
961
+ | COMMENT ON TYPE_P typename IS comment_text
962
+ | COMMENT ON DOMAIN_P typename IS comment_text
963
+ | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
964
+ | COMMENT ON FUNCTION function_with_argtypes IS comment_text
965
+ | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
966
+ | COMMENT ON CONSTRAINT name ON any_name IS comment_text
967
+ | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
968
+ | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
969
+ | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
970
+ | COMMENT ON ROUTINE function_with_argtypes IS comment_text
971
+ | COMMENT ON TRANSFORM FOR typename LANGUAGE name IS comment_text
972
+ | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
973
+ | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
974
+ | COMMENT ON LARGE_P OBJECT_P numericonly IS comment_text
975
+ | COMMENT ON CAST OPEN_PAREN typename AS typename CLOSE_PAREN IS comment_text
976
+ */
977
+ }, {
978
+ key: "visitCommentstmt",
979
+ value: function visitCommentstmt(ctx) {
980
+ var note = ctx.comment_text().accept(this);
981
+ if (ctx.object_type_any_name()) {
982
+ var objectType = ctx.object_type_any_name().accept(this);
983
+ if (!objectType) return;
984
+ if (objectType === COMMENT_OBJECT_TYPE.TABLE) {
985
+ var names = ctx.any_name().accept(this);
986
+ var tableName = (0, _lodash.last)(names);
987
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
988
+ var table = findTable(this.data.tables, schemaName, tableName);
989
+ if (!table) return;
990
+ var _note = ctx.comment_text().accept(this);
991
+ table.note = {
992
+ value: _note
993
+ };
994
+ }
995
+ }
996
+ if (ctx.COLUMN()) {
997
+ var _names = ctx.any_name().accept(this);
998
+ var fieldName = (0, _lodash.last)(_names);
999
+ var _tableName = _names.length > 1 ? _names[_names.length - 2] : undefined;
1000
+ var _schemaName = _names.length > 2 ? _names[_names.length - 3] : undefined;
1001
+ var _table2 = findTable(this.data.tables, _schemaName, _tableName);
1002
+ var field = _table2.fields.find(function (field) {
1003
+ return field.name === fieldName;
1004
+ });
1005
+ if (!field) return;
1006
+ var _note2 = ctx.comment_text().accept(this);
1007
+ field.note = {
1008
+ value: _note2
1009
+ };
1010
+ }
1011
+ }
1012
+
1013
+ // sconst | NULL_P
1014
+ }, {
1015
+ key: "visitComment_text",
1016
+ value: function visitComment_text(ctx) {
1017
+ if (ctx.NULL_P()) return null;
1018
+ return ctx.sconst().accept(this);
1019
+ }
1020
+
1021
+ // anysconst opt_uescape
1022
+ }, {
1023
+ key: "visitSconst",
1024
+ value: function visitSconst(ctx) {
1025
+ return ctx.anysconst().accept(this);
1026
+ }
1027
+
1028
+ // StringConstant | UnicodeEscapeStringConstant | BeginDollarStringConstant DollarText* EndDollarStringConstant | EscapeStringConstant
1029
+ }, {
1030
+ key: "visitAnysconst",
1031
+ value: function visitAnysconst(ctx) {
1032
+ var value = ctx.getChild(0).getText();
1033
+ return value.slice(1, value.length - 1);
1034
+ }
1035
+
1036
+ // TABLE | SEQUENCE | VIEW | MATERIALIZED VIEW | INDEX | FOREIGN TABLE | COLLATION | CONVERSION_P | STATISTICS | TEXT_P SEARCH PARSER | TEXT_P SEARCH DICTIONARY | TEXT_P SEARCH TEMPLATE | TEXT_P SEARCH CONFIGURATION
1037
+ }, {
1038
+ key: "visitObject_type_any_name",
1039
+ value: function visitObject_type_any_name(ctx) {
1040
+ if (ctx.TABLE()) return COMMENT_OBJECT_TYPE.TABLE;
1041
+ }
1042
+
1043
+ // colid attrs?
1044
+ }, {
1045
+ key: "visitAny_name",
1046
+ value: function visitAny_name(ctx) {
1047
+ var r = [ctx.colid().accept(this)];
1048
+ if (ctx.attrs()) {
1049
+ r.push.apply(r, _toConsumableArray(ctx.attrs().accept(this)));
1050
+ }
1051
+ return r;
1052
+ }
1053
+
1054
+ // (DOT attr_name)+
1055
+ }, {
1056
+ key: "visitAttrs",
1057
+ value: function visitAttrs(ctx) {
1058
+ var _this10 = this;
1059
+ return ctx.attr_name().map(function (a) {
1060
+ return a.accept(_this10);
1061
+ });
1062
+ }
1063
+
1064
+ /*
1065
+ CREATE opt_or_replace AGGREGATE func_name aggr_args definition
1066
+ | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
1067
+ | CREATE OPERATOR any_operator definition
1068
+ | CREATE TYPE_P any_name definition
1069
+ | CREATE TYPE_P any_name
1070
+ | CREATE TYPE_P any_name AS OPEN_PAREN opttablefuncelementlist CLOSE_PAREN
1071
+ | CREATE TYPE_P any_name AS ENUM_P OPEN_PAREN opt_enum_val_list CLOSE_PAREN
1072
+ | CREATE TYPE_P any_name AS RANGE definition
1073
+ | CREATE TEXT_P SEARCH PARSER any_name definition
1074
+ | CREATE TEXT_P SEARCH DICTIONARY any_name definition
1075
+ | CREATE TEXT_P SEARCH TEMPLATE any_name definition
1076
+ | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
1077
+ | CREATE COLLATION any_name definition
1078
+ | CREATE COLLATION IF_P NOT EXISTS any_name definition
1079
+ | CREATE COLLATION any_name FROM any_name
1080
+ | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
1081
+ */
1082
+ }, {
1083
+ key: "visitDefinestmt",
1084
+ value: function visitDefinestmt(ctx) {
1085
+ if (ctx.TYPE_P() && ctx.opt_enum_val_list()) {
1086
+ var names = ctx.any_name(0).accept(this);
1087
+ var enumName = (0, _lodash.last)(names);
1088
+ var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
1089
+ var values = ctx.opt_enum_val_list().accept(this).map(function (e) {
1090
+ return {
1091
+ name: e
1092
+ };
1093
+ });
1094
+ if (!values) return;
1095
+
1096
+ // enum is a keyworkd
1097
+ var _enum = new _AST.Enum({
1098
+ name: enumName,
1099
+ schemaName: schemaName,
1100
+ values: values
1101
+ });
1102
+ this.data.enums.push(_enum.toJSON());
1103
+ }
1104
+ }
1105
+
1106
+ // enum_val_list |
1107
+ }, {
1108
+ key: "visitOpt_enum_val_list",
1109
+ value: function visitOpt_enum_val_list(ctx) {
1110
+ var _ctx$enum_val_list;
1111
+ return (_ctx$enum_val_list = ctx.enum_val_list()) === null || _ctx$enum_val_list === void 0 ? void 0 : _ctx$enum_val_list.accept(this);
1112
+ }
1113
+
1114
+ // sconst (COMMA sconst)*
1115
+ }, {
1116
+ key: "visitEnum_val_list",
1117
+ value: function visitEnum_val_list(ctx) {
1118
+ var _this11 = this;
1119
+ return ctx.sconst().map(function (s) {
1120
+ return s.accept(_this11);
1121
+ });
1122
+ }
1123
+ }]);
1124
+ return PostgresASTGen;
1125
+ }(_PostgreSQLParserVisitor["default"]);
1126
+ exports["default"] = PostgresASTGen;