@dbml/core 3.6.2 → 3.7.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/connectors/ utils.js +11 -0
- package/lib/{connector/index.js → connectors/connector.js} +23 -23
- package/lib/connectors/dbml.js +170 -0
- package/lib/connectors/mssqlConnector.js +391 -0
- package/lib/connectors/mysqlConnector.js +490 -0
- package/lib/{parse/connection/postgres/utils.js → connectors/postgresConnector.js} +106 -168
- package/lib/export/DbmlExporter.js +5 -2
- 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 +32 -1
- package/lib/index.js +0 -0
- package/lib/model_structure/config.js +0 -0
- package/lib/model_structure/database.js +0 -0
- 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 +0 -0
- package/lib/parse/ANTLR/ASTGeneration/AST.js +1 -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 +0 -0
- package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +0 -0
- 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 +0 -0
- package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +1 -1
- package/lib/parse/ANTLR/README.md +0 -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/DatabaseGenerator.js +118 -0
- package/lib/parse/Parser.js +0 -0
- package/lib/parse/buildParser.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 +7 -3
- package/types/export/ModelExporter.d.ts +0 -0
- package/types/export/index.d.ts +0 -0
- package/types/import/index.d.ts +2 -0
- package/types/index.d.ts +0 -0
- package/types/model_structure/database.d.ts +0 -0
- 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 +0 -0
- package/types/parse/error.d.ts +0 -0
- package/lib/parse/DatabaseConnector.js +0 -87
- package/lib/parse/connection/ConnectionASTGeneration.js +0 -21
- package/lib/parse/connection/postgres/PostgresConnectionASTGen.js +0 -63
|
@@ -4,9 +4,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.fetchSchemaJson = void 0;
|
|
8
8
|
var _pg = require("pg");
|
|
9
|
-
var _AST = require("../../ANTLR/ASTGeneration/AST");
|
|
10
9
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
10
|
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."); }
|
|
12
11
|
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); }
|
|
@@ -16,27 +15,39 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
16
15
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
17
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
18
17
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /* eslint-disable camelcase */
|
|
19
|
-
var
|
|
18
|
+
var getValidatedClient = /*#__PURE__*/function () {
|
|
20
19
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection) {
|
|
21
20
|
var client;
|
|
22
21
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
23
22
|
while (1) switch (_context.prev = _context.next) {
|
|
24
23
|
case 0:
|
|
25
|
-
client = new _pg.Client(connection);
|
|
26
|
-
|
|
27
|
-
return console.log('PG connection error:', err);
|
|
28
|
-
});
|
|
24
|
+
client = new _pg.Client(connection);
|
|
25
|
+
_context.prev = 1;
|
|
29
26
|
_context.next = 4;
|
|
30
27
|
return client.connect();
|
|
31
28
|
case 4:
|
|
29
|
+
_context.next = 6;
|
|
30
|
+
return client.query('SELECT 1');
|
|
31
|
+
case 6:
|
|
32
32
|
return _context.abrupt("return", client);
|
|
33
|
-
case
|
|
33
|
+
case 9:
|
|
34
|
+
_context.prev = 9;
|
|
35
|
+
_context.t0 = _context["catch"](1);
|
|
36
|
+
// Log the error and handle it as per your application's requirement
|
|
37
|
+
console.error('PostgreSQL connection error:', _context.t0);
|
|
38
|
+
|
|
39
|
+
// Ensure to close the client in case of failure
|
|
40
|
+
_context.next = 14;
|
|
41
|
+
return client.end();
|
|
42
|
+
case 14:
|
|
43
|
+
throw _context.t0;
|
|
44
|
+
case 15:
|
|
34
45
|
case "end":
|
|
35
46
|
return _context.stop();
|
|
36
47
|
}
|
|
37
|
-
}, _callee);
|
|
48
|
+
}, _callee, null, [[1, 9]]);
|
|
38
49
|
}));
|
|
39
|
-
return function
|
|
50
|
+
return function getValidatedClient(_x) {
|
|
40
51
|
return _ref.apply(this, arguments);
|
|
41
52
|
};
|
|
42
53
|
}();
|
|
@@ -66,12 +77,12 @@ var getDbdefault = function getDbdefault(data_type, column_default, default_type
|
|
|
66
77
|
};
|
|
67
78
|
}
|
|
68
79
|
if (default_type === 'string') {
|
|
69
|
-
var
|
|
80
|
+
var defaultValues = column_default.split('::')[0];
|
|
70
81
|
var isJson = data_type === 'json' || data_type === 'jsonb';
|
|
71
82
|
var type = isJson ? 'expression' : 'string';
|
|
72
83
|
return {
|
|
73
84
|
type: type,
|
|
74
|
-
value:
|
|
85
|
+
value: defaultValues.slice(1, -1)
|
|
75
86
|
};
|
|
76
87
|
}
|
|
77
88
|
return {
|
|
@@ -79,7 +90,7 @@ var getDbdefault = function getDbdefault(data_type, column_default, default_type
|
|
|
79
90
|
value: column_default
|
|
80
91
|
};
|
|
81
92
|
};
|
|
82
|
-
var
|
|
93
|
+
var generateField = function generateField(row) {
|
|
83
94
|
var column_name = row.column_name,
|
|
84
95
|
data_type = row.data_type,
|
|
85
96
|
character_maximum_length = row.character_maximum_length,
|
|
@@ -113,24 +124,25 @@ var generateRawField = function generateRawField(row) {
|
|
|
113
124
|
}
|
|
114
125
|
};
|
|
115
126
|
};
|
|
116
|
-
var
|
|
127
|
+
var generateTablesAndFields = /*#__PURE__*/function () {
|
|
117
128
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(client) {
|
|
118
|
-
var
|
|
129
|
+
var fields, tablesAndFieldsSql, tablesAndFieldsResult, tables;
|
|
119
130
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
120
131
|
while (1) switch (_context2.prev = _context2.next) {
|
|
121
132
|
case 0:
|
|
122
|
-
|
|
123
|
-
tablesAndFieldsSql = "\n SELECT\n t.table_schema,\n t.table_name,\n c.column_name,\n c.data_type,\n c.character_maximum_length,\n c.numeric_precision,\n c.numeric_scale,\n c.udt_schema,\n c.udt_name,\n c.identity_increment,\n c.is_nullable,\n c.column_default,\n CASE\n WHEN c.column_default IS NULL THEN NULL\n WHEN c.column_default LIKE 'nextval(%' THEN 'increment'\n WHEN c.column_default LIKE '''%' THEN 'string'\n WHEN c.column_default = 'true' OR c.column_default = 'false' THEN 'boolean'\n WHEN c.column_default ~ '^-?[0-9]+(.[0-9]+)?$' THEN 'number'\n ELSE 'expression'\n END AS default_type,\n
|
|
133
|
+
fields = {};
|
|
134
|
+
tablesAndFieldsSql = "\n WITH comments AS (\n SELECT\n pc.relname AS table_name,\n pn.nspname AS table_schema,\n pa.attname AS column_name,\n pd.description\n FROM\n pg_description pd\n JOIN\n pg_class pc ON pd.objoid = pc.oid\n JOIN\n pg_namespace pn ON pc.relnamespace = pn.oid\n LEFT JOIN\n pg_attribute pa ON pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum\n WHERE\n pc.relkind = 'r'\n AND pn.nspname NOT IN ('pg_catalog', 'information_schema')\n )\n SELECT\n t.table_schema,\n t.table_name,\n c.column_name,\n c.data_type,\n c.character_maximum_length,\n c.numeric_precision,\n c.numeric_scale,\n c.udt_schema,\n c.udt_name,\n c.identity_increment,\n c.is_nullable,\n c.column_default,\n CASE\n WHEN c.column_default IS NULL THEN NULL\n WHEN c.column_default LIKE 'nextval(%' THEN 'increment'\n WHEN c.column_default LIKE '''%' THEN 'string'\n WHEN c.column_default = 'true' OR c.column_default = 'false' THEN 'boolean'\n WHEN c.column_default ~ '^-?[0-9]+(.[0-9]+)?$' THEN 'number'\n ELSE 'expression'\n END AS default_type,\n (SELECT description FROM comments WHERE table_name = t.table_name AND table_schema = t.table_schema AND column_name IS NULL) AS table_comment,\n (SELECT description FROM comments WHERE table_name = t.table_name AND table_schema = t.table_schema AND column_name = c.column_name) AS column_comment\n FROM\n information_schema.columns c\n JOIN\n information_schema.tables t ON c.table_name = t.table_name AND c.table_schema = t.table_schema\n WHERE\n t.table_type = 'BASE TABLE'\n AND t.table_schema NOT IN ('pg_catalog', 'information_schema')\n ORDER BY\n t.table_schema,\n t.table_name,\n c.ordinal_position\n ;\n ";
|
|
124
135
|
_context2.next = 4;
|
|
125
136
|
return client.query(tablesAndFieldsSql);
|
|
126
137
|
case 4:
|
|
127
138
|
tablesAndFieldsResult = _context2.sent;
|
|
128
|
-
|
|
139
|
+
tables = tablesAndFieldsResult.rows.reduce(function (acc, row) {
|
|
129
140
|
var table_schema = row.table_schema,
|
|
130
141
|
table_name = row.table_name,
|
|
131
142
|
table_comment = row.table_comment;
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
var key = "".concat(table_schema, ".").concat(table_name);
|
|
144
|
+
if (!acc[key]) {
|
|
145
|
+
acc[key] = {
|
|
134
146
|
name: table_name,
|
|
135
147
|
schemaName: table_schema,
|
|
136
148
|
note: table_comment ? {
|
|
@@ -140,14 +152,14 @@ var generateRawTablesAndFields = /*#__PURE__*/function () {
|
|
|
140
152
|
}
|
|
141
153
|
};
|
|
142
154
|
}
|
|
143
|
-
if (!
|
|
144
|
-
var field =
|
|
145
|
-
|
|
155
|
+
if (!fields[key]) fields[key] = [];
|
|
156
|
+
var field = generateField(row);
|
|
157
|
+
fields[key].push(field);
|
|
146
158
|
return acc;
|
|
147
159
|
}, {});
|
|
148
160
|
return _context2.abrupt("return", {
|
|
149
|
-
|
|
150
|
-
|
|
161
|
+
tables: Object.values(tables),
|
|
162
|
+
fields: fields
|
|
151
163
|
});
|
|
152
164
|
case 7:
|
|
153
165
|
case "end":
|
|
@@ -155,84 +167,70 @@ var generateRawTablesAndFields = /*#__PURE__*/function () {
|
|
|
155
167
|
}
|
|
156
168
|
}, _callee2);
|
|
157
169
|
}));
|
|
158
|
-
return function
|
|
170
|
+
return function generateTablesAndFields(_x2) {
|
|
159
171
|
return _ref2.apply(this, arguments);
|
|
160
172
|
};
|
|
161
173
|
}();
|
|
162
|
-
var
|
|
174
|
+
var generateRawRefs = /*#__PURE__*/function () {
|
|
163
175
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(client) {
|
|
164
|
-
var
|
|
176
|
+
var refs, refsListSql, refsQueryResult;
|
|
165
177
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
166
178
|
while (1) switch (_context3.prev = _context3.next) {
|
|
167
179
|
case 0:
|
|
168
|
-
registeredFK = [];
|
|
169
180
|
refs = [];
|
|
170
|
-
refsListSql = "\n SELECT\n tc.table_schema,\n tc.
|
|
171
|
-
_context3.next =
|
|
181
|
+
refsListSql = "\n SELECT\n tc.table_schema,\n tc.table_name,\n tc.constraint_name as fk_constraint_name,\n STRING_AGG(DISTINCT kcu.column_name, ',') AS column_names,\n ccu.table_schema AS foreign_table_schema,\n ccu.table_name AS foreign_table_name,\n STRING_AGG(DISTINCT ccu.column_name, ',') AS foreign_column_names,\n tc.constraint_type,\n rc.delete_rule AS on_delete,\n rc.update_rule AS on_update\n FROM information_schema.table_constraints AS tc\n JOIN information_schema.key_column_usage AS kcu\n ON tc.constraint_name = kcu.constraint_name\n AND tc.table_schema = kcu.table_schema\n JOIN information_schema.constraint_column_usage AS ccu\n ON ccu.constraint_name = tc.constraint_name\n JOIN information_schema.referential_constraints AS rc\n ON tc.constraint_name = rc.constraint_name\n AND tc.table_schema = rc.constraint_schema\n WHERE tc.constraint_type = 'FOREIGN KEY'\n AND tc.table_schema NOT IN ('pg_catalog', 'information_schema')\n GROUP BY\n tc.table_schema,\n tc.table_name,\n tc.constraint_name,\n ccu.table_schema,\n ccu.table_name,\n tc.constraint_type,\n rc.delete_rule,\n rc.update_rule\n ORDER BY\n tc.table_schema,\n tc.table_name;\n ";
|
|
182
|
+
_context3.next = 4;
|
|
172
183
|
return client.query(refsListSql);
|
|
173
|
-
case
|
|
184
|
+
case 4:
|
|
174
185
|
refsQueryResult = _context3.sent;
|
|
175
186
|
refsQueryResult.rows.forEach(function (refRow) {
|
|
176
187
|
var table_schema = refRow.table_schema,
|
|
177
|
-
|
|
188
|
+
fk_constraint_name = refRow.fk_constraint_name,
|
|
178
189
|
table_name = refRow.table_name,
|
|
179
|
-
|
|
190
|
+
column_names = refRow.column_names,
|
|
180
191
|
foreign_table_schema = refRow.foreign_table_schema,
|
|
181
192
|
foreign_table_name = refRow.foreign_table_name,
|
|
182
|
-
|
|
193
|
+
foreign_column_names = refRow.foreign_column_names,
|
|
183
194
|
on_delete = refRow.on_delete,
|
|
184
195
|
on_update = refRow.on_update;
|
|
185
|
-
var ep1 =
|
|
196
|
+
var ep1 = {
|
|
186
197
|
tableName: table_name,
|
|
187
198
|
schemaName: table_schema,
|
|
188
|
-
fieldNames:
|
|
199
|
+
fieldNames: column_names.split(','),
|
|
189
200
|
relation: '*'
|
|
190
|
-
}
|
|
191
|
-
var ep2 =
|
|
201
|
+
};
|
|
202
|
+
var ep2 = {
|
|
192
203
|
tableName: foreign_table_name,
|
|
193
204
|
schemaName: foreign_table_schema,
|
|
194
|
-
fieldNames:
|
|
205
|
+
fieldNames: foreign_column_names.split(','),
|
|
195
206
|
relation: '1'
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
name:
|
|
207
|
+
};
|
|
208
|
+
refs.push({
|
|
209
|
+
name: fk_constraint_name,
|
|
199
210
|
endpoints: [ep1, ep2],
|
|
200
|
-
onDelete: on_delete,
|
|
201
|
-
onUpdate: on_update
|
|
211
|
+
onDelete: on_delete === 'NO ACTION' ? null : on_delete,
|
|
212
|
+
onUpdate: on_update === 'NO ACTION' ? null : on_update
|
|
202
213
|
});
|
|
203
|
-
if (!registeredFK.some(function (fk) {
|
|
204
|
-
return fk.table_schema === table_schema && fk.table_name === table_name && fk.column_name === column_name && fk.foreign_table_schema === foreign_table_schema && fk.foreign_table_name === foreign_table_name && fk.foreign_column_name === foreign_column_name;
|
|
205
|
-
})) {
|
|
206
|
-
refs.push(ref.toJSON());
|
|
207
|
-
registeredFK.push({
|
|
208
|
-
table_schema: table_schema,
|
|
209
|
-
table_name: table_name,
|
|
210
|
-
column_name: column_name,
|
|
211
|
-
foreign_table_schema: foreign_table_schema,
|
|
212
|
-
foreign_table_name: foreign_table_name,
|
|
213
|
-
foreign_column_name: foreign_column_name
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
214
|
});
|
|
217
215
|
return _context3.abrupt("return", refs);
|
|
218
|
-
case
|
|
216
|
+
case 7:
|
|
219
217
|
case "end":
|
|
220
218
|
return _context3.stop();
|
|
221
219
|
}
|
|
222
220
|
}, _callee3);
|
|
223
221
|
}));
|
|
224
|
-
return function
|
|
222
|
+
return function generateRawRefs(_x3) {
|
|
225
223
|
return _ref3.apply(this, arguments);
|
|
226
224
|
};
|
|
227
225
|
}();
|
|
228
|
-
var
|
|
226
|
+
var generateIndexes = /*#__PURE__*/function () {
|
|
229
227
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(client) {
|
|
230
|
-
var indexListSql, indexListResult, _indexListResult$rows,
|
|
228
|
+
var indexListSql, indexListResult, _indexListResult$rows, outOfLineConstraints, inlineConstraints, indexes, tableConstraints;
|
|
231
229
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
232
230
|
while (1) switch (_context4.prev = _context4.next) {
|
|
233
231
|
case 0:
|
|
234
232
|
// const tableConstraints = {};
|
|
235
|
-
indexListSql = "\n WITH user_tables AS (\n SELECT tablename\n FROM pg_tables\n WHERE schemaname
|
|
233
|
+
indexListSql = "\n WITH user_tables AS (\n SELECT\n schemaname AS tableschema,\n tablename\n FROM pg_tables\n WHERE schemaname NOT IN ('pg_catalog', 'information_schema') -- Exclude system schemas\n AND tablename NOT LIKE 'pg_%' -- Exclude PostgreSQL system tables\n AND tablename NOT LIKE 'sql_%' -- Exclude SQL standard tables\n ),\n index_info AS (\n SELECT\n t.relname AS table_name,\n i.relname AS index_name,\n ix.indisunique AS is_unique,\n ix.indisprimary AS is_primary,\n am.amname AS index_type,\n array_to_string(array_agg(a.attname ORDER BY x.n), ', ') AS columns,\n pg_get_expr(ix.indexprs, ix.indrelid) AS expressions,\n CASE\n WHEN ix.indisprimary THEN 'PRIMARY KEY'\n WHEN ix.indisunique THEN 'UNIQUE'\n ELSE NULL\n END AS constraint_type\n FROM\n pg_class t\n JOIN pg_index ix ON t.oid = ix.indrelid\n JOIN pg_class i ON i.oid = ix.indexrelid\n LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)\n JOIN pg_am am ON i.relam = am.oid\n LEFT JOIN generate_subscripts(ix.indkey, 1) AS x(n) ON a.attnum = ix.indkey[x.n]\n WHERE\n t.relkind = 'r'\n AND t.relname NOT LIKE 'pg_%'\n AND t.relname NOT LIKE 'sql_%'\n GROUP BY\n t.relname, i.relname, ix.indisunique, ix.indisprimary, am.amname, ix.indexprs, ix.indrelid\n )\n SELECT\n ut.tableschema AS table_schema,\n ut.tablename AS table_name,\n ii.index_name,\n ii.is_unique,\n ii.is_primary,\n ii.index_type,\n ii.columns,\n ii.expressions,\n ii.constraint_type -- Added constraint type\n FROM\n user_tables ut\n LEFT JOIN\n index_info ii ON ut.tablename = ii.table_name\n WHERE ii.columns IS NOT NULL\n ORDER BY\n ut.tablename,\n ii.constraint_type,\n ii.index_name\n ;\n ";
|
|
236
234
|
_context4.next = 3;
|
|
237
235
|
return client.query(indexListSql);
|
|
238
236
|
case 3:
|
|
@@ -241,18 +239,21 @@ var generateRawIndexes = /*#__PURE__*/function () {
|
|
|
241
239
|
var constraint_type = row.constraint_type,
|
|
242
240
|
columns = row.columns;
|
|
243
241
|
if (columns === 'null' || columns.trim() === '') return acc;
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
var isSingleColumn = columns.split(',').length === 1;
|
|
243
|
+
var isInlineConstraint = isSingleColumn && (constraint_type === 'PRIMARY KEY' || constraint_type === 'UNIQUE');
|
|
244
|
+
if (isInlineConstraint) {
|
|
245
|
+
acc.inlineConstraints.push(row);
|
|
246
246
|
} else {
|
|
247
|
-
acc.
|
|
247
|
+
acc.outOfLineConstraints.push(row);
|
|
248
248
|
}
|
|
249
249
|
return acc;
|
|
250
250
|
}, {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}),
|
|
254
|
-
|
|
255
|
-
var
|
|
251
|
+
outOfLineConstraints: [],
|
|
252
|
+
inlineConstraints: []
|
|
253
|
+
}), outOfLineConstraints = _indexListResult$rows.outOfLineConstraints, inlineConstraints = _indexListResult$rows.inlineConstraints;
|
|
254
|
+
indexes = outOfLineConstraints.reduce(function (acc, indexRow) {
|
|
255
|
+
var table_schema = indexRow.table_schema,
|
|
256
|
+
table_name = indexRow.table_name,
|
|
256
257
|
index_name = indexRow.index_name,
|
|
257
258
|
index_type = indexRow.index_type,
|
|
258
259
|
columns = indexRow.columns,
|
|
@@ -274,34 +275,37 @@ var generateRawIndexes = /*#__PURE__*/function () {
|
|
|
274
275
|
type: index_type,
|
|
275
276
|
columns: [].concat(_toConsumableArray(indexColumns), _toConsumableArray(indexExpressions))
|
|
276
277
|
};
|
|
277
|
-
|
|
278
|
-
|
|
278
|
+
var key = "".concat(table_schema, ".").concat(table_name);
|
|
279
|
+
if (acc[key]) {
|
|
280
|
+
acc[key].push(index);
|
|
279
281
|
} else {
|
|
280
|
-
acc[
|
|
282
|
+
acc[key] = [index];
|
|
281
283
|
}
|
|
282
284
|
return acc;
|
|
283
285
|
}, {});
|
|
284
|
-
tableConstraints =
|
|
285
|
-
var
|
|
286
|
+
tableConstraints = inlineConstraints.reduce(function (acc, row) {
|
|
287
|
+
var table_schema = row.table_schema,
|
|
288
|
+
table_name = row.table_name,
|
|
286
289
|
columns = row.columns,
|
|
287
290
|
constraint_type = row.constraint_type;
|
|
288
|
-
|
|
291
|
+
var key = "".concat(table_schema, ".").concat(table_name);
|
|
292
|
+
if (!acc[key]) acc[key] = {};
|
|
289
293
|
var columnNames = columns.split(',').map(function (column) {
|
|
290
294
|
return column.trim();
|
|
291
295
|
});
|
|
292
296
|
columnNames.forEach(function (columnName) {
|
|
293
|
-
if (!acc[
|
|
297
|
+
if (!acc[key][columnName]) acc[key][columnName] = {};
|
|
294
298
|
if (constraint_type === 'PRIMARY KEY') {
|
|
295
|
-
acc[
|
|
299
|
+
acc[key][columnName].pk = true;
|
|
296
300
|
}
|
|
297
|
-
if (constraint_type === 'UNIQUE' && !acc[
|
|
298
|
-
acc[
|
|
301
|
+
if (constraint_type === 'UNIQUE' && !acc[key][columnName].pk) {
|
|
302
|
+
acc[key][columnName].unique = true;
|
|
299
303
|
}
|
|
300
304
|
});
|
|
301
305
|
return acc;
|
|
302
306
|
}, {});
|
|
303
307
|
return _context4.abrupt("return", {
|
|
304
|
-
|
|
308
|
+
indexes: indexes,
|
|
305
309
|
tableConstraints: tableConstraints
|
|
306
310
|
});
|
|
307
311
|
case 8:
|
|
@@ -310,7 +314,7 @@ var generateRawIndexes = /*#__PURE__*/function () {
|
|
|
310
314
|
}
|
|
311
315
|
}, _callee4);
|
|
312
316
|
}));
|
|
313
|
-
return function
|
|
317
|
+
return function generateIndexes(_x4) {
|
|
314
318
|
return _ref4.apply(this, arguments);
|
|
315
319
|
};
|
|
316
320
|
}();
|
|
@@ -352,111 +356,45 @@ var generateRawEnums = /*#__PURE__*/function () {
|
|
|
352
356
|
return _ref5.apply(this, arguments);
|
|
353
357
|
};
|
|
354
358
|
}();
|
|
355
|
-
var
|
|
356
|
-
return rawEnums.map(function (rawEnum) {
|
|
357
|
-
var name = rawEnum.name,
|
|
358
|
-
schemaName = rawEnum.schemaName,
|
|
359
|
-
values = rawEnum.values;
|
|
360
|
-
return new _AST.Enum({
|
|
361
|
-
name: name,
|
|
362
|
-
schemaName: schemaName,
|
|
363
|
-
values: values
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
var createFields = function createFields(rawFields, fieldsConstraints) {
|
|
368
|
-
return rawFields.map(function (field) {
|
|
369
|
-
var constraints = fieldsConstraints[field.name] || {};
|
|
370
|
-
var f = new _AST.Field({
|
|
371
|
-
name: field.name,
|
|
372
|
-
type: field.type,
|
|
373
|
-
dbdefault: field.dbdefault,
|
|
374
|
-
not_null: field.not_null,
|
|
375
|
-
increment: field.increment,
|
|
376
|
-
pk: constraints.pk,
|
|
377
|
-
unique: constraints.unique,
|
|
378
|
-
note: field.note
|
|
379
|
-
});
|
|
380
|
-
return f;
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
|
-
var createIndexes = function createIndexes(rawIndexes) {
|
|
384
|
-
return rawIndexes.map(function (rawIndex) {
|
|
385
|
-
var name = rawIndex.name,
|
|
386
|
-
unique = rawIndex.unique,
|
|
387
|
-
primary = rawIndex.primary,
|
|
388
|
-
type = rawIndex.type,
|
|
389
|
-
columns = rawIndex.columns;
|
|
390
|
-
var index = new _AST.Index({
|
|
391
|
-
name: name,
|
|
392
|
-
unique: unique,
|
|
393
|
-
pk: primary,
|
|
394
|
-
type: type,
|
|
395
|
-
columns: columns
|
|
396
|
-
});
|
|
397
|
-
return index;
|
|
398
|
-
});
|
|
399
|
-
};
|
|
400
|
-
var createTables = function createTables(rawTables, rawFields, rawIndexes, tableConstraints) {
|
|
401
|
-
return rawTables.map(function (rawTable) {
|
|
402
|
-
var name = rawTable.name,
|
|
403
|
-
schemaName = rawTable.schemaName,
|
|
404
|
-
note = rawTable.note;
|
|
405
|
-
var constraints = tableConstraints[name] || {};
|
|
406
|
-
var fields = createFields(rawFields[name], constraints);
|
|
407
|
-
var indexes = createIndexes(rawIndexes[name] || []);
|
|
408
|
-
return new _AST.Table({
|
|
409
|
-
name: name,
|
|
410
|
-
schemaName: schemaName,
|
|
411
|
-
fields: fields,
|
|
412
|
-
indexes: indexes,
|
|
413
|
-
note: note
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
};
|
|
417
|
-
var generateRawDb = /*#__PURE__*/function () {
|
|
359
|
+
var fetchSchemaJson = /*#__PURE__*/function () {
|
|
418
360
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(connection) {
|
|
419
|
-
var client, tablesAndFieldsRes,
|
|
361
|
+
var client, tablesAndFieldsRes, indexesRes, refsRes, enumsRes, res, _res$, tables, fields, _res$2, indexes, tableConstraints, refs, enums;
|
|
420
362
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
421
363
|
while (1) switch (_context6.prev = _context6.next) {
|
|
422
364
|
case 0:
|
|
423
365
|
_context6.next = 2;
|
|
424
|
-
return
|
|
366
|
+
return getValidatedClient(connection);
|
|
425
367
|
case 2:
|
|
426
368
|
client = _context6.sent;
|
|
427
|
-
tablesAndFieldsRes =
|
|
428
|
-
|
|
429
|
-
refsRes =
|
|
430
|
-
|
|
369
|
+
tablesAndFieldsRes = generateTablesAndFields(client);
|
|
370
|
+
indexesRes = generateIndexes(client);
|
|
371
|
+
refsRes = generateRawRefs(client);
|
|
372
|
+
enumsRes = generateRawEnums(client);
|
|
431
373
|
_context6.next = 9;
|
|
432
|
-
return Promise.all([tablesAndFieldsRes,
|
|
374
|
+
return Promise.all([tablesAndFieldsRes, indexesRes, refsRes, enumsRes]);
|
|
433
375
|
case 9:
|
|
434
376
|
res = _context6.sent;
|
|
435
377
|
client.end();
|
|
436
|
-
_res$ = res[0],
|
|
437
|
-
_res$2 = res[1],
|
|
378
|
+
_res$ = res[0], tables = _res$.tables, fields = _res$.fields;
|
|
379
|
+
_res$2 = res[1], indexes = _res$2.indexes, tableConstraints = _res$2.tableConstraints;
|
|
438
380
|
refs = res[2];
|
|
439
|
-
|
|
440
|
-
_context6.prev = 15;
|
|
441
|
-
tables = createTables(rawTables, rawFields, rawIndexes, tableConstraints);
|
|
442
|
-
enums = createEnums(rawEnums);
|
|
381
|
+
enums = res[3];
|
|
443
382
|
return _context6.abrupt("return", {
|
|
444
383
|
tables: tables,
|
|
384
|
+
fields: fields,
|
|
445
385
|
refs: refs,
|
|
446
|
-
enums: enums
|
|
386
|
+
enums: enums,
|
|
387
|
+
indexes: indexes,
|
|
388
|
+
tableConstraints: tableConstraints
|
|
447
389
|
});
|
|
448
|
-
case
|
|
449
|
-
_context6.prev = 21;
|
|
450
|
-
_context6.t0 = _context6["catch"](15);
|
|
451
|
-
throw new Error(_context6.t0);
|
|
452
|
-
case 24:
|
|
390
|
+
case 16:
|
|
453
391
|
case "end":
|
|
454
392
|
return _context6.stop();
|
|
455
393
|
}
|
|
456
|
-
}, _callee6
|
|
394
|
+
}, _callee6);
|
|
457
395
|
}));
|
|
458
|
-
return function
|
|
396
|
+
return function fetchSchemaJson(_x6) {
|
|
459
397
|
return _ref6.apply(this, arguments);
|
|
460
398
|
};
|
|
461
399
|
}();
|
|
462
|
-
exports.
|
|
400
|
+
exports.fetchSchemaJson = fetchSchemaJson;
|
|
@@ -93,8 +93,11 @@ var DbmlExporter = /*#__PURE__*/function () {
|
|
|
93
93
|
value += "".concat(field.dbdefault.value);
|
|
94
94
|
break;
|
|
95
95
|
case 'string':
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
{
|
|
97
|
+
var quote = field.dbdefault.value.includes('\n') ? "'''" : "'";
|
|
98
|
+
value += "".concat(quote).concat(field.dbdefault.value).concat(quote);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
98
101
|
case 'expression':
|
|
99
102
|
value += "`".concat(field.dbdefault.value, "`");
|
|
100
103
|
break;
|
|
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
|
@@ -4,15 +4,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
+
var _databaseGenerator = require("../parse/databaseGenerator");
|
|
8
|
+
var _connector = require("../connectors/connector");
|
|
7
9
|
var _Parser = _interopRequireDefault(require("../parse/Parser"));
|
|
8
10
|
var _ModelExporter = _interopRequireDefault(require("../export/ModelExporter"));
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
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); }
|
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
16
|
function _import(str, format) {
|
|
11
17
|
var database = new _Parser["default"]().parse(str, format);
|
|
12
18
|
var dbml = _ModelExporter["default"]["export"](database.normalize(), 'dbml');
|
|
13
19
|
return dbml;
|
|
14
20
|
}
|
|
21
|
+
function generateDbml(_x, _x2) {
|
|
22
|
+
return _generateDbml.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
function _generateDbml() {
|
|
25
|
+
_generateDbml = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection, format) {
|
|
26
|
+
var schemaJson, database, dbml;
|
|
27
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
28
|
+
while (1) switch (_context.prev = _context.next) {
|
|
29
|
+
case 0:
|
|
30
|
+
_context.next = 2;
|
|
31
|
+
return (0, _connector.fetchSchemaJson)(connection, format);
|
|
32
|
+
case 2:
|
|
33
|
+
schemaJson = _context.sent;
|
|
34
|
+
database = (0, _databaseGenerator.generateDatabase)(schemaJson);
|
|
35
|
+
dbml = _ModelExporter["default"]["export"](database.normalize(), 'dbml');
|
|
36
|
+
return _context.abrupt("return", dbml);
|
|
37
|
+
case 6:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}, _callee);
|
|
42
|
+
}));
|
|
43
|
+
return _generateDbml.apply(this, arguments);
|
|
44
|
+
}
|
|
15
45
|
var _default = {
|
|
16
|
-
"import": _import
|
|
46
|
+
"import": _import,
|
|
47
|
+
generateDbml: generateDbml
|
|
17
48
|
};
|
|
18
49
|
exports["default"] = _default;
|
package/lib/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|