@dbml/core 3.10.1 → 3.11.0-alpha-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/lib/export/DbmlExporter.js +0 -0
- package/lib/export/JsonExporter.js +0 -0
- package/lib/export/ModelExporter.js +0 -0
- package/lib/export/MysqlExporter.js +0 -0
- package/lib/export/OracleExporter.js +0 -0
- package/lib/export/PostgresExporter.js +0 -0
- package/lib/export/README.md +0 -0
- package/lib/export/SqlServerExporter.js +0 -0
- package/lib/export/index.js +0 -0
- package/lib/export/utils.js +0 -0
- package/lib/import/index.js +0 -0
- package/lib/index.js +0 -0
- package/lib/model_structure/config.js +0 -0
- package/lib/model_structure/database.js +6 -2
- package/lib/model_structure/dbState.js +0 -0
- package/lib/model_structure/element.js +0 -0
- package/lib/model_structure/endpoint.js +0 -0
- package/lib/model_structure/enum.js +0 -0
- package/lib/model_structure/enumValue.js +0 -0
- package/lib/model_structure/field.js +0 -0
- package/lib/model_structure/indexColumn.js +0 -0
- package/lib/model_structure/indexes.js +0 -0
- package/lib/model_structure/ref.js +0 -0
- package/lib/model_structure/schema.js +0 -0
- package/lib/model_structure/stickyNote.js +0 -0
- package/lib/model_structure/table.js +0 -0
- package/lib/model_structure/tableGroup.js +0 -0
- package/lib/model_structure/utils.js +6 -0
- package/lib/parse/ANTLR/ASTGeneration/AST.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/constants.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/helpers.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/index.js +21 -5
- package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +393 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +165 -4
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +0 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +236 -5
- package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +0 -0
- package/lib/parse/ANTLR/README.md +0 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.g4 +1294 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.interp +3643 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.js +1255 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.tokens +2385 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.g4 +6307 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.interp +3034 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.js +3 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParser.tokens +2385 -0
- package/lib/parse/ANTLR/parsers/mssql/TSqlParserVisitor.js +5732 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +0 -0
- package/lib/parse/ANTLR/parsers/postgresql/README.md +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.g4 +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.interp +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.js +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.tokens +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.g4 +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.interp +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.js +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.tokens +0 -0
- package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParserVisitor.js +0 -0
- package/lib/parse/Parser.js +10 -0
- package/lib/parse/buildParser.js +0 -0
- package/lib/parse/databaseGenerator.js +0 -0
- package/lib/parse/dbml/parser.pegjs +0 -0
- package/lib/parse/dbmlParser.js +0 -0
- package/lib/parse/error.js +0 -0
- package/lib/parse/mssql/base_parsers.js +0 -0
- package/lib/parse/mssql/column_definition/actions.js +0 -0
- package/lib/parse/mssql/column_definition/index.js +0 -0
- package/lib/parse/mssql/constraint_definition/actions.js +0 -0
- package/lib/parse/mssql/constraint_definition/index.js +0 -0
- package/lib/parse/mssql/expression.js +0 -0
- package/lib/parse/mssql/fk_definition/actions.js +0 -0
- package/lib/parse/mssql/fk_definition/index.js +0 -0
- package/lib/parse/mssql/index.js +0 -0
- package/lib/parse/mssql/index_definition/actions.js +0 -0
- package/lib/parse/mssql/index_definition/index.js +0 -0
- package/lib/parse/mssql/keyword_parsers.js +0 -0
- package/lib/parse/mssql/keyword_utils.js +0 -0
- package/lib/parse/mssql/statements/actions.js +0 -0
- package/lib/parse/mssql/statements/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/alter_table/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/comments/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/comments/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_index/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_index/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_table/actions.js +0 -0
- package/lib/parse/mssql/statements/statement_types/create_table/index.js +0 -0
- package/lib/parse/mssql/statements/statement_types/index.js +0 -0
- package/lib/parse/mssql/utils.js +0 -0
- package/lib/parse/mssql/whitespaces.js +0 -0
- package/lib/parse/mssqlParser.js +0 -0
- package/lib/parse/mysql/parser.pegjs +0 -0
- package/lib/parse/mysqlParser.js +0 -0
- package/lib/parse/postgresParser.js +0 -0
- package/lib/parse/postgresql/Base_rules.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Commands.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Comment.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_index.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Create_type/Create_type_range.pegjs +0 -0
- package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +0 -0
- package/lib/parse/postgresql/Expression.pegjs +0 -0
- package/lib/parse/postgresql/InitializerUtils.pegjs +0 -0
- package/lib/parse/postgresql/Keywords.pegjs +0 -0
- package/lib/parse/postgresql/get_parser.js +0 -0
- package/lib/parse/postgresql/parser.pegjs +0 -0
- package/lib/parse/schemarb/parser.pegjs +0 -0
- package/lib/parse/schemarbParser.js +0 -0
- package/lib/utils/version.js +0 -0
- package/package.json +3 -3
- package/types/export/ModelExporter.d.ts +0 -0
- package/types/export/index.d.ts +0 -0
- package/types/import/index.d.ts +0 -0
- package/types/index.d.ts +0 -0
- package/types/model_structure/database.d.ts +16 -1
- package/types/model_structure/dbState.d.ts +0 -0
- package/types/model_structure/element.d.ts +0 -0
- package/types/model_structure/endpoint.d.ts +0 -0
- package/types/model_structure/enum.d.ts +0 -0
- package/types/model_structure/enumValue.d.ts +0 -0
- package/types/model_structure/field.d.ts +0 -0
- package/types/model_structure/indexColumn.d.ts +0 -0
- package/types/model_structure/indexes.d.ts +0 -0
- package/types/model_structure/ref.d.ts +0 -0
- package/types/model_structure/schema.d.ts +0 -0
- package/types/model_structure/stickyNote.d.ts +0 -0
- package/types/model_structure/table.d.ts +0 -0
- package/types/model_structure/tableGroup.d.ts +0 -0
- package/types/parse/Parser.d.ts +2 -1
- package/types/parse/error.d.ts +0 -0
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/export/README.md
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/export/index.js
CHANGED
|
File without changes
|
package/lib/export/utils.js
CHANGED
|
File without changes
|
package/lib/import/index.js
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -53,7 +53,9 @@ var Database = /*#__PURE__*/function (_Element) {
|
|
|
53
53
|
_ref$project = _ref.project,
|
|
54
54
|
project = _ref$project === void 0 ? {} : _ref$project,
|
|
55
55
|
_ref$aliases = _ref.aliases,
|
|
56
|
-
aliases = _ref$aliases === void 0 ? [] : _ref$aliases
|
|
56
|
+
aliases = _ref$aliases === void 0 ? [] : _ref$aliases,
|
|
57
|
+
_ref$records = _ref.records,
|
|
58
|
+
records = _ref$records === void 0 ? {} : _ref$records;
|
|
57
59
|
_classCallCheck(this, Database);
|
|
58
60
|
_this = _super.call(this);
|
|
59
61
|
_this.dbState = new _dbState["default"]();
|
|
@@ -67,6 +69,7 @@ var Database = /*#__PURE__*/function (_Element) {
|
|
|
67
69
|
_this.name = project.name;
|
|
68
70
|
_this.token = project.token;
|
|
69
71
|
_this.aliases = aliases;
|
|
72
|
+
_this.records = records;
|
|
70
73
|
_this.processNotes(notes);
|
|
71
74
|
// The process order is important. Do not change !
|
|
72
75
|
_this.processSchemas(schemas);
|
|
@@ -291,7 +294,8 @@ var Database = /*#__PURE__*/function (_Element) {
|
|
|
291
294
|
enumValues: {},
|
|
292
295
|
indexes: {},
|
|
293
296
|
indexColumns: {},
|
|
294
|
-
fields: {}
|
|
297
|
+
fields: {},
|
|
298
|
+
records: this.records
|
|
295
299
|
};
|
|
296
300
|
this.schemas.forEach(function (schema) {
|
|
297
301
|
return schema.normalize(normalizedModel);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getFullTableName = getFullTableName;
|
|
6
7
|
exports.shouldPrintSchema = shouldPrintSchema;
|
|
7
8
|
exports.shouldPrintSchemaName = shouldPrintSchemaName;
|
|
8
9
|
var _config = require("./config");
|
|
@@ -11,4 +12,9 @@ function shouldPrintSchema(schema) {
|
|
|
11
12
|
}
|
|
12
13
|
function shouldPrintSchemaName(schemaName) {
|
|
13
14
|
return schemaName !== _config.DEFAULT_SCHEMA_NAME;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// TODO: This is an ad hoc function for parsing inserts. It should be replaced with a more robust solution
|
|
18
|
+
function getFullTableName(schemaName, tableName) {
|
|
19
|
+
return "".concat(schemaName && shouldPrintSchemaName(schemaName) ? "".concat(schemaName, ".") : '').concat(tableName);
|
|
14
20
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -15,6 +15,9 @@ var _SnowflakeLexer = _interopRequireDefault(require("../parsers/snowflake/Snowf
|
|
|
15
15
|
var _SnowflakeParser = _interopRequireDefault(require("../parsers/snowflake/SnowflakeParser"));
|
|
16
16
|
var _SnowflakeASTGen = _interopRequireDefault(require("./snowflake/SnowflakeASTGen"));
|
|
17
17
|
var _ParserErrorListener = _interopRequireDefault(require("./ParserErrorListener"));
|
|
18
|
+
var _TSqlLexer = _interopRequireDefault(require("../parsers/mssql/TSqlLexer"));
|
|
19
|
+
var _TSqlParser = _interopRequireDefault(require("../parsers/mssql/TSqlParser"));
|
|
20
|
+
var _MssqlASTGen = _interopRequireDefault(require("./mssql/MssqlASTGen"));
|
|
18
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
22
|
/* eslint-disable import/no-named-as-default-member */
|
|
20
23
|
/* eslint-disable import/no-named-as-default */
|
|
@@ -50,16 +53,29 @@ function parse(input, format) {
|
|
|
50
53
|
if (errorListener.errors.length) throw errorListener.errors;
|
|
51
54
|
break;
|
|
52
55
|
}
|
|
53
|
-
case '
|
|
56
|
+
case 'mssql':
|
|
54
57
|
{
|
|
55
|
-
var _lexer2 = new
|
|
58
|
+
var _lexer2 = new _TSqlLexer["default"](chars);
|
|
56
59
|
var _tokens2 = new _antlr["default"].CommonTokenStream(_lexer2);
|
|
57
|
-
var _parser2 = new
|
|
60
|
+
var _parser2 = new _TSqlParser["default"](_tokens2);
|
|
58
61
|
_parser2.buildParseTrees = true;
|
|
59
62
|
_parser2.removeErrorListeners();
|
|
60
63
|
_parser2.addErrorListener(errorListener);
|
|
61
|
-
var _parseTree2 = _parser2.
|
|
62
|
-
database = _parseTree2.accept(new
|
|
64
|
+
var _parseTree2 = _parser2.tsql_file();
|
|
65
|
+
database = _parseTree2.accept(new _MssqlASTGen["default"]());
|
|
66
|
+
if (errorListener.errors.length) throw errorListener.errors;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'snowflake':
|
|
70
|
+
{
|
|
71
|
+
var _lexer3 = new _SnowflakeLexer["default"](chars);
|
|
72
|
+
var _tokens3 = new _antlr["default"].CommonTokenStream(_lexer3);
|
|
73
|
+
var _parser3 = new _SnowflakeParser["default"](_tokens3);
|
|
74
|
+
_parser3.buildParseTrees = true;
|
|
75
|
+
_parser3.removeErrorListeners();
|
|
76
|
+
_parser3.addErrorListener(errorListener);
|
|
77
|
+
var _parseTree3 = _parser3.snowflake_file();
|
|
78
|
+
database = _parseTree3.accept(new _SnowflakeASTGen["default"]());
|
|
63
79
|
if (errorListener.errors.length) throw errorListener.errors;
|
|
64
80
|
break;
|
|
65
81
|
}
|
|
@@ -0,0 +1,393 @@
|
|
|
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 _utils = require("../../../../model_structure/utils");
|
|
10
|
+
var _TSqlParserVisitor2 = _interopRequireDefault(require("../../parsers/mssql/TSqlParserVisitor"));
|
|
11
|
+
var _constants = require("../constants");
|
|
12
|
+
var _helpers = require("../helpers");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
15
|
+
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."); }
|
|
16
|
+
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); }
|
|
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 _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; }
|
|
20
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
21
|
+
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); } }
|
|
22
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
23
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
24
|
+
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); }
|
|
25
|
+
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); }
|
|
26
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
27
|
+
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); }; }
|
|
28
|
+
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); }
|
|
29
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
30
|
+
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; } }
|
|
31
|
+
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 */
|
|
32
|
+
var MssqlASTGen = /*#__PURE__*/function (_TSqlParserVisitor) {
|
|
33
|
+
_inherits(MssqlASTGen, _TSqlParserVisitor);
|
|
34
|
+
var _super = _createSuper(MssqlASTGen);
|
|
35
|
+
function MssqlASTGen() {
|
|
36
|
+
var _this;
|
|
37
|
+
_classCallCheck(this, MssqlASTGen);
|
|
38
|
+
_this = _super.call(this);
|
|
39
|
+
_this.data = {
|
|
40
|
+
schemas: [],
|
|
41
|
+
tables: [],
|
|
42
|
+
refs: [],
|
|
43
|
+
enums: [],
|
|
44
|
+
tableGroups: [],
|
|
45
|
+
aliases: [],
|
|
46
|
+
project: {},
|
|
47
|
+
records: {}
|
|
48
|
+
};
|
|
49
|
+
return _this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// tsql_file
|
|
53
|
+
// : batch* EOF
|
|
54
|
+
// | execute_body_batch go_statement* EOF
|
|
55
|
+
// ;
|
|
56
|
+
_createClass(MssqlASTGen, [{
|
|
57
|
+
key: "visitTsql_file",
|
|
58
|
+
value: function visitTsql_file(ctx) {
|
|
59
|
+
var _this2 = this;
|
|
60
|
+
ctx.batch().forEach(function (batch) {
|
|
61
|
+
return batch.accept(_this2);
|
|
62
|
+
});
|
|
63
|
+
return this.data;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// batch
|
|
67
|
+
// : go_statement
|
|
68
|
+
// | execute_body_batch? (go_statement | sql_clauses+) go_statement*
|
|
69
|
+
// | batch_level_statement go_statement*
|
|
70
|
+
// ;
|
|
71
|
+
}, {
|
|
72
|
+
key: "visitBatch",
|
|
73
|
+
value: function visitBatch(ctx) {
|
|
74
|
+
var _this3 = this;
|
|
75
|
+
if (ctx.sql_clauses()) {
|
|
76
|
+
ctx.sql_clauses().forEach(function (sqlClause) {
|
|
77
|
+
return sqlClause.accept(_this3);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// sql_clauses
|
|
83
|
+
// : dml_clause SEMI?
|
|
84
|
+
// | cfl_statement SEMI?
|
|
85
|
+
// | another_statement SEMI?
|
|
86
|
+
// | ddl_clause SEMI?
|
|
87
|
+
// | dbcc_clause SEMI?
|
|
88
|
+
// | backup_statement SEMI?
|
|
89
|
+
// | SEMI
|
|
90
|
+
// ;
|
|
91
|
+
}, {
|
|
92
|
+
key: "visitSql_clauses",
|
|
93
|
+
value: function visitSql_clauses(ctx) {
|
|
94
|
+
if (ctx.dml_clause()) {
|
|
95
|
+
ctx.dml_clause().accept(this);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// dml_clause
|
|
100
|
+
// : merge_statement
|
|
101
|
+
// | delete_statement
|
|
102
|
+
// | insert_statement
|
|
103
|
+
// | select_statement_standalone
|
|
104
|
+
// | update_statement
|
|
105
|
+
// ;
|
|
106
|
+
}, {
|
|
107
|
+
key: "visitDml_clause",
|
|
108
|
+
value: function visitDml_clause(ctx) {
|
|
109
|
+
if (ctx.insert_statement()) {
|
|
110
|
+
ctx.insert_statement().accept(this);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// insert_statement
|
|
115
|
+
// : with_expression? INSERT (TOP '(' expression ')' PERCENT?)? INTO? (
|
|
116
|
+
// ddl_object
|
|
117
|
+
// | rowset_function_limited
|
|
118
|
+
// ) with_table_hints? ('(' insert_column_name_list ')')? output_clause? insert_statement_value for_clause? option_clause? ';'?
|
|
119
|
+
// ;
|
|
120
|
+
}, {
|
|
121
|
+
key: "visitInsert_statement",
|
|
122
|
+
value: function visitInsert_statement(ctx) {
|
|
123
|
+
var _this$data$records$fu;
|
|
124
|
+
// [ 'users' ]
|
|
125
|
+
// [ 'test', 'users' ]
|
|
126
|
+
// [ 'db', 'test', 'users' ]
|
|
127
|
+
// [ 'server', 'db', 'test', 'users' ]
|
|
128
|
+
// The last: table name
|
|
129
|
+
// The second-last: schema name
|
|
130
|
+
var names = ctx.ddl_object().accept(this);
|
|
131
|
+
var tableName = (0, _lodash.last)(names);
|
|
132
|
+
var schemaName = names.length > 1 ? (0, _lodash.nth)(names, -2) : undefined;
|
|
133
|
+
var columns = ctx.insert_column_name_list() ? ctx.insert_column_name_list().accept(this) : [];
|
|
134
|
+
var values = ctx.insert_statement_value().accept(this);
|
|
135
|
+
|
|
136
|
+
// handle insert into all columns
|
|
137
|
+
if (columns.length === 0 || values.length === 0) {
|
|
138
|
+
// temporarily ignore
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
var fullTableName = (0, _utils.getFullTableName)(schemaName, tableName);
|
|
142
|
+
if (!this.data.records[fullTableName]) {
|
|
143
|
+
this.data.records[fullTableName] = {
|
|
144
|
+
schemaName: schemaName,
|
|
145
|
+
tableName: tableName,
|
|
146
|
+
columns: columns,
|
|
147
|
+
values: []
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
(_this$data$records$fu = this.data.records[fullTableName].values).push.apply(_this$data$records$fu, _toConsumableArray(values));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ddl_object
|
|
154
|
+
// : full_table_name
|
|
155
|
+
// | LOCAL_ID
|
|
156
|
+
// ;
|
|
157
|
+
}, {
|
|
158
|
+
key: "visitDdl_object",
|
|
159
|
+
value: function visitDdl_object(ctx) {
|
|
160
|
+
return ctx.full_table_name().accept(this);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// full_table_name
|
|
164
|
+
// : (
|
|
165
|
+
// linkedServer = id_ '.' '.' schema = id_ '.'
|
|
166
|
+
// | server = id_ '.' database = id_ '.' schema = id_ '.'
|
|
167
|
+
// | database = id_ '.' schema = id_? '.'
|
|
168
|
+
// | schema = id_ '.'
|
|
169
|
+
// )? table = id_
|
|
170
|
+
// ;
|
|
171
|
+
}, {
|
|
172
|
+
key: "visitFull_table_name",
|
|
173
|
+
value: function visitFull_table_name(ctx) {
|
|
174
|
+
var _this4 = this;
|
|
175
|
+
return ctx.id_().map(function (id) {
|
|
176
|
+
return id.accept(_this4);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// id_
|
|
181
|
+
// : ID
|
|
182
|
+
// | TEMP_ID
|
|
183
|
+
// | DOUBLE_QUOTE_ID
|
|
184
|
+
// | DOUBLE_QUOTE_BLANK
|
|
185
|
+
// | SQUARE_BRACKET_ID
|
|
186
|
+
// | keyword
|
|
187
|
+
// | RAW
|
|
188
|
+
// ;
|
|
189
|
+
}, {
|
|
190
|
+
key: "visitId_",
|
|
191
|
+
value: function visitId_(ctx) {
|
|
192
|
+
if (ctx.DOUBLE_QUOTE_ID() || ctx.SQUARE_BRACKET_ID()) return (0, _helpers.getOriginalText)(ctx).slice(1, -1);
|
|
193
|
+
return (0, _helpers.getOriginalText)(ctx);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// insert_column_name_list
|
|
197
|
+
// : col += insert_column_id (',' col += insert_column_id)*
|
|
198
|
+
// ;
|
|
199
|
+
}, {
|
|
200
|
+
key: "visitInsert_column_name_list",
|
|
201
|
+
value: function visitInsert_column_name_list(ctx) {
|
|
202
|
+
var _this5 = this;
|
|
203
|
+
var columns = ctx.insert_column_id().map(function (column) {
|
|
204
|
+
return column.accept(_this5);
|
|
205
|
+
});
|
|
206
|
+
return (0, _lodash.flattenDepth)(columns, 1);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// insert_column_id
|
|
210
|
+
// : (ignore += id_? '.')* id_
|
|
211
|
+
// ;
|
|
212
|
+
|
|
213
|
+
// insert_statement_value
|
|
214
|
+
// : table_value_constructor
|
|
215
|
+
// | derived_table
|
|
216
|
+
// | execute_statement
|
|
217
|
+
// | DEFAULT VALUES
|
|
218
|
+
// ;
|
|
219
|
+
}, {
|
|
220
|
+
key: "visitInsert_statement_value",
|
|
221
|
+
value: function visitInsert_statement_value(ctx) {
|
|
222
|
+
if (!ctx.table_value_constructor()) return [];
|
|
223
|
+
var rawValues = ctx.table_value_constructor().accept(this);
|
|
224
|
+
return rawValues;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// table_value_constructor
|
|
228
|
+
// : VALUES '(' exps += expression_list_ ')' (',' '(' exps += expression_list_ ')')*
|
|
229
|
+
// ;
|
|
230
|
+
}, {
|
|
231
|
+
key: "visitTable_value_constructor",
|
|
232
|
+
value: function visitTable_value_constructor(ctx) {
|
|
233
|
+
var _this6 = this;
|
|
234
|
+
return ctx.expression_list_().map(function (expression) {
|
|
235
|
+
return expression.accept(_this6);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// expression_list_
|
|
240
|
+
// : exp += expression (',' exp += expression)*
|
|
241
|
+
// ;
|
|
242
|
+
}, {
|
|
243
|
+
key: "visitExpression_list_",
|
|
244
|
+
value: function visitExpression_list_(ctx) {
|
|
245
|
+
var _this7 = this;
|
|
246
|
+
return ctx.expression().map(function (expression) {
|
|
247
|
+
return expression.accept(_this7);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// expression
|
|
252
|
+
// : primitive_expression
|
|
253
|
+
// | function_call
|
|
254
|
+
// | expression '.' (value_call | query_call | exist_call | modify_call)
|
|
255
|
+
// | expression '.' hierarchyid_call
|
|
256
|
+
// | expression COLLATE id_
|
|
257
|
+
// | case_expression
|
|
258
|
+
// | full_column_name
|
|
259
|
+
// | bracket_expression
|
|
260
|
+
// | unary_operator_expression
|
|
261
|
+
// | expression op = ('*' | '/' | '%') expression
|
|
262
|
+
// | expression op = ('+' | '-' | '&' | '^' | '|' | '||') expression
|
|
263
|
+
// | expression time_zone
|
|
264
|
+
// | over_clause
|
|
265
|
+
// | DOLLAR_ACTION
|
|
266
|
+
// ;
|
|
267
|
+
}, {
|
|
268
|
+
key: "visitExpression",
|
|
269
|
+
value: function visitExpression(ctx) {
|
|
270
|
+
if (ctx.primitive_expression()) {
|
|
271
|
+
return ctx.primitive_expression().accept(this);
|
|
272
|
+
}
|
|
273
|
+
if (ctx.function_call()) {
|
|
274
|
+
return ctx.function_call().accept(this);
|
|
275
|
+
}
|
|
276
|
+
if (ctx.unary_operator_expression()) {
|
|
277
|
+
return ctx.unary_operator_expression().accept(this);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Default case for any other expression type
|
|
281
|
+
return {
|
|
282
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
283
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// primitive_constant
|
|
288
|
+
// : STRING // string, datetime or uniqueidentifier
|
|
289
|
+
// | BINARY
|
|
290
|
+
// | (DECIMAL | REAL | FLOAT) // float or decimal
|
|
291
|
+
// | dollar = '$' ('-' | '+')? (DECIMAL | FLOAT) // money
|
|
292
|
+
// | parameter
|
|
293
|
+
// ;
|
|
294
|
+
}, {
|
|
295
|
+
key: "visitPrimitive_constant",
|
|
296
|
+
value: function visitPrimitive_constant(ctx) {
|
|
297
|
+
if (ctx.STRING() || ctx.BINARY()) {
|
|
298
|
+
return {
|
|
299
|
+
value: ctx.getText(),
|
|
300
|
+
type: _constants.DATA_TYPE.STRING
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (ctx.DOLLAR()) {
|
|
304
|
+
var dollar = (0, _lodash.first)(ctx.children).getText();
|
|
305
|
+
var sign = ctx.children.length > 2 ? (0, _lodash.nth)(ctx.children, -2) : '';
|
|
306
|
+
var value = (0, _lodash.last)(ctx.children).getText();
|
|
307
|
+
return {
|
|
308
|
+
value: "".concat(dollar).concat(sign).concat(value),
|
|
309
|
+
type: _constants.DATA_TYPE.STRING
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (ctx.REAL() || ctx.DECIMAL() || ctx.FLOAT()) {
|
|
313
|
+
return {
|
|
314
|
+
value: ctx.getText(),
|
|
315
|
+
type: _constants.DATA_TYPE.NUMBER
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
value: ctx.getText(),
|
|
320
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// function_call
|
|
325
|
+
// : ranking_windowed_function # RANKING_WINDOWED_FUNC
|
|
326
|
+
// | aggregate_windowed_function # AGGREGATE_WINDOWED_FUNC
|
|
327
|
+
// | analytic_windowed_function # ANALYTIC_WINDOWED_FUNC
|
|
328
|
+
// | built_in_functions # BUILT_IN_FUNC
|
|
329
|
+
// | scalar_function_name '(' expression_list_? ')' # SCALAR_FUNCTION
|
|
330
|
+
// | freetext_function # FREE_TEXT
|
|
331
|
+
// | partition_function # PARTITION_FUNC
|
|
332
|
+
// | hierarchyid_static_method # HIERARCHYID_METHOD
|
|
333
|
+
// ;
|
|
334
|
+
|
|
335
|
+
// See packages/dbml-core/src/parse/ANTLR/parsers/mssql/TSqlParser.g4 at line 4338
|
|
336
|
+
}, {
|
|
337
|
+
key: "visitBUILT_IN_FUNC",
|
|
338
|
+
value: function visitBUILT_IN_FUNC(ctx) {
|
|
339
|
+
return {
|
|
340
|
+
value: (0, _helpers.getOriginalText)(ctx),
|
|
341
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// unary_operator_expression
|
|
346
|
+
// : '~' expression
|
|
347
|
+
// | op = ('+' | '-') expression
|
|
348
|
+
// ;
|
|
349
|
+
}, {
|
|
350
|
+
key: "visitUnary_operator_expression",
|
|
351
|
+
value: function visitUnary_operator_expression(ctx) {
|
|
352
|
+
var operator = ctx.children[0].getText();
|
|
353
|
+
var expression = ctx.expression().accept(this);
|
|
354
|
+
return {
|
|
355
|
+
value: "".concat(operator).concat(expression.value),
|
|
356
|
+
type: expression.type
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// data_type
|
|
361
|
+
// : scaled = (VARCHAR | NVARCHAR | BINARY_KEYWORD | VARBINARY_KEYWORD | SQUARE_BRACKET_ID) '(' MAX ')'
|
|
362
|
+
// | ext_type = id_ '(' scale = DECIMAL ',' prec = DECIMAL ')'
|
|
363
|
+
// | ext_type = id_ '(' scale = DECIMAL ')'
|
|
364
|
+
// | ext_type = id_ IDENTITY ('(' seed = DECIMAL ',' inc = DECIMAL ')')?
|
|
365
|
+
// | double_prec = DOUBLE PRECISION?
|
|
366
|
+
// | unscaled_type = id_
|
|
367
|
+
// ;
|
|
368
|
+
}, {
|
|
369
|
+
key: "visitData_type",
|
|
370
|
+
value: function visitData_type(ctx) {
|
|
371
|
+
return ctx.getText();
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
key: "visitPrimitive_expression",
|
|
375
|
+
value: function visitPrimitive_expression(ctx) {
|
|
376
|
+
if (ctx.NULL_()) {
|
|
377
|
+
return {
|
|
378
|
+
value: ctx.getText(),
|
|
379
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
if (ctx.primitive_constant()) {
|
|
383
|
+
return ctx.primitive_constant().accept(this);
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
value: ctx.getText(),
|
|
387
|
+
type: _constants.DATA_TYPE.EXPRESSION
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}]);
|
|
391
|
+
return MssqlASTGen;
|
|
392
|
+
}(_TSqlParserVisitor2["default"]);
|
|
393
|
+
exports["default"] = MssqlASTGen;
|