mysqlsyncr 1.0.50 → 1.0.54

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.
@@ -0,0 +1,333 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getDatabases = exports.getDatabaseStructure = void 0;
8
+ var _parsers = require("./parsers.js");
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _promises = _interopRequireDefault(require("fs/promises"));
11
+ var _loggers = require("./loggers.js");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
14
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
17
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
18
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
19
+ var getDatabases = exports.getDatabases = /*#__PURE__*/function () {
20
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection) {
21
+ var databases;
22
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
23
+ while (1) switch (_context.prev = _context.next) {
24
+ case 0:
25
+ _context.next = 2;
26
+ return connection.query('SHOW DATABASES');
27
+ case 2:
28
+ databases = _context.sent;
29
+ return _context.abrupt("return", databases.map(function (db) {
30
+ return db.Database;
31
+ }).filter(function (db) {
32
+ return !['information_schema', 'mysql', 'performance_schema', 'sys'].includes(db);
33
+ }));
34
+ case 4:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }, _callee);
39
+ }));
40
+ return function getDatabases(_x) {
41
+ return _ref.apply(this, arguments);
42
+ };
43
+ }();
44
+ var getDatabaseStructure = exports.getDatabaseStructure = /*#__PURE__*/function () {
45
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(connection, database, command, options) {
46
+ var tables, procedures, views, dbDir, tableDir, tableRows, _iterator, _step, row, tableName, createTableRow, createTableSQL, parsedTable, _tableDir, filePath, routineRows, _iterator2, _step2, _row, createSQLrow, createSQL, _filePath, triggerRows, _iterator3, _step3, _row2, triggerName, _tableName, triggerDefinitionRow, triggerDefinition, _tableDir2, triggerFilePath, viewRows, _iterator4, _step4, _row3, viewName, viewDefinition, _filePath2;
47
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
48
+ while (1) switch (_context2.prev = _context2.next) {
49
+ case 0:
50
+ if (!(connection.state === 'disconnected')) {
51
+ _context2.next = 3;
52
+ break;
53
+ }
54
+ _context2.next = 3;
55
+ return connection.reconnect();
56
+ case 3:
57
+ _context2.next = 5;
58
+ return connection.query("USE `".concat(database, "`"));
59
+ case 5:
60
+ // Switch to the target database
61
+ tables = {};
62
+ procedures = [];
63
+ views = {};
64
+ dbDir = _path["default"].join(options.output, database); // Use argv.output for the base path
65
+ // Create the output directory for the database if it doesn't exist
66
+ if (!(command === 'dump')) {
67
+ _context2.next = 13;
68
+ break;
69
+ }
70
+ tableDir = _path["default"].join(dbDir, 'tables'); // Subfolder for table SQL files
71
+ _context2.next = 13;
72
+ return _promises["default"].mkdir(tableDir, {
73
+ recursive: true
74
+ });
75
+ case 13:
76
+ _context2.next = 15;
77
+ return connection.query('SHOW FULL TABLES WHERE Table_Type != "VIEW"');
78
+ case 15:
79
+ tableRows = _context2.sent;
80
+ _iterator = _createForOfIteratorHelper(tableRows);
81
+ _context2.prev = 17;
82
+ _iterator.s();
83
+ case 19:
84
+ if ((_step = _iterator.n()).done) {
85
+ _context2.next = 41;
86
+ break;
87
+ }
88
+ row = _step.value;
89
+ tableName = Object.values(row)[0]; // Get the first value in the row object
90
+ if (tableName) {
91
+ _context2.next = 25;
92
+ break;
93
+ }
94
+ (0, _loggers.logger)("Undefined table name found in database ".concat(database), row);
95
+ return _context2.abrupt("continue", 39);
96
+ case 25:
97
+ _context2.next = 27;
98
+ return connection.query("SHOW CREATE TABLE `".concat(tableName, "`"));
99
+ case 27:
100
+ createTableRow = _context2.sent;
101
+ createTableSQL = createTableRow[0]['Create Table'];
102
+ parsedTable = (0, _parsers.parseCreateTableSQL)(createTableSQL); // Structure the table object
103
+ tables[tableName] = {
104
+ columns: parsedTable.columns,
105
+ // Array of columns
106
+ indexes: parsedTable.indexes,
107
+ // Array of indexes
108
+ constraints: parsedTable.constraints,
109
+ // Array of constraints
110
+ triggers: [],
111
+ // Initialize triggers array
112
+ createSQL: createTableSQL // Store the CREATE TABLE SQL if needed
113
+ };
114
+
115
+ // Save the CREATE TABLE statement to an individual SQL file for each table
116
+ if (!(command === 'dump')) {
117
+ _context2.next = 39;
118
+ break;
119
+ }
120
+ _tableDir = _path["default"].join(dbDir, 'tables'); // Subfolder for table SQL files
121
+ filePath = _path["default"].join(_tableDir, "".concat(tableName, ".sql")); // Use the table directory for file saving
122
+ _context2.next = 36;
123
+ return _promises["default"].mkdir(_path["default"].dirname(filePath), {
124
+ recursive: true
125
+ });
126
+ case 36:
127
+ _context2.next = 38;
128
+ return _promises["default"].writeFile(filePath, "".concat(createTableSQL, "\n"), 'utf-8');
129
+ case 38:
130
+ (0, _loggers.logger)("Table structure saved to: ".concat(filePath));
131
+ case 39:
132
+ _context2.next = 19;
133
+ break;
134
+ case 41:
135
+ _context2.next = 46;
136
+ break;
137
+ case 43:
138
+ _context2.prev = 43;
139
+ _context2.t0 = _context2["catch"](17);
140
+ _iterator.e(_context2.t0);
141
+ case 46:
142
+ _context2.prev = 46;
143
+ _iterator.f();
144
+ return _context2.finish(46);
145
+ case 49:
146
+ _context2.next = 51;
147
+ return connection.query("SHOW PROCEDURE STATUS WHERE Db = ?", [database]);
148
+ case 51:
149
+ routineRows = _context2.sent;
150
+ _iterator2 = _createForOfIteratorHelper(routineRows);
151
+ _context2.prev = 53;
152
+ _iterator2.s();
153
+ case 55:
154
+ if ((_step2 = _iterator2.n()).done) {
155
+ _context2.next = 71;
156
+ break;
157
+ }
158
+ _row = _step2.value;
159
+ _context2.next = 59;
160
+ return connection.query("SHOW CREATE PROCEDURE `".concat(_row.Name, "`"));
161
+ case 59:
162
+ createSQLrow = _context2.sent;
163
+ createSQL = createSQLrow[0]['Create Procedure'];
164
+ procedures.push({
165
+ Name: _row.Name,
166
+ Definition: createSQL
167
+ }); // Add procedure names to the array
168
+ if (!(command === 'dump')) {
169
+ _context2.next = 69;
170
+ break;
171
+ }
172
+ _filePath = _path["default"].join(dbDir, 'procedures', "".concat(_row.Name, ".sql")); // Use the table directory for file saving
173
+ _context2.next = 66;
174
+ return _promises["default"].mkdir(_path["default"].dirname(_filePath), {
175
+ recursive: true
176
+ });
177
+ case 66:
178
+ _context2.next = 68;
179
+ return _promises["default"].writeFile(_filePath, "".concat(createSQL, "\n"), 'utf-8');
180
+ case 68:
181
+ (0, _loggers.logger)("Procedure definition saved to: ".concat(_filePath));
182
+ case 69:
183
+ _context2.next = 55;
184
+ break;
185
+ case 71:
186
+ _context2.next = 76;
187
+ break;
188
+ case 73:
189
+ _context2.prev = 73;
190
+ _context2.t1 = _context2["catch"](53);
191
+ _iterator2.e(_context2.t1);
192
+ case 76:
193
+ _context2.prev = 76;
194
+ _iterator2.f();
195
+ return _context2.finish(76);
196
+ case 79:
197
+ _context2.next = 81;
198
+ return connection.query("\n SELECT TRIGGER_NAME, EVENT_OBJECT_TABLE\n FROM INFORMATION_SCHEMA.TRIGGERS\n WHERE TRIGGER_SCHEMA = ?\n ", [database]);
199
+ case 81:
200
+ triggerRows = _context2.sent;
201
+ _iterator3 = _createForOfIteratorHelper(triggerRows);
202
+ _context2.prev = 83;
203
+ _iterator3.s();
204
+ case 85:
205
+ if ((_step3 = _iterator3.n()).done) {
206
+ _context2.next = 108;
207
+ break;
208
+ }
209
+ _row2 = _step3.value;
210
+ triggerName = _row2.TRIGGER_NAME;
211
+ _tableName = _row2.EVENT_OBJECT_TABLE; // Ensure triggerDefinition is defined before using it
212
+ _context2.next = 91;
213
+ return connection.query("SHOW CREATE TRIGGER `".concat(triggerName, "`"));
214
+ case 91:
215
+ triggerDefinitionRow = _context2.sent;
216
+ triggerDefinition = triggerDefinitionRow[0]['SQL Original Statement'];
217
+ if (!triggerDefinition) {
218
+ _context2.next = 105;
219
+ break;
220
+ }
221
+ tables[_tableName].triggers.push({
222
+ Name: triggerName,
223
+ Definition: triggerDefinition
224
+ });
225
+ if (!(command === 'dump')) {
226
+ _context2.next = 103;
227
+ break;
228
+ }
229
+ _tableDir2 = _path["default"].join(dbDir, 'tables'); // Subfolder for table SQL files
230
+ triggerFilePath = _path["default"].join(_tableDir2, 'triggers', "".concat(triggerName, ".sql"));
231
+ _context2.next = 100;
232
+ return _promises["default"].mkdir(_path["default"].dirname(triggerFilePath), {
233
+ recursive: true
234
+ });
235
+ case 100:
236
+ _context2.next = 102;
237
+ return _promises["default"].writeFile(triggerFilePath, "".concat(triggerDefinition, "\n"), 'utf-8');
238
+ case 102:
239
+ (0, _loggers.logger)("Trigger definition saved to: ".concat(triggerFilePath));
240
+ case 103:
241
+ _context2.next = 106;
242
+ break;
243
+ case 105:
244
+ console.warn("Trigger ".concat(triggerName, " has no action statement."));
245
+ case 106:
246
+ _context2.next = 85;
247
+ break;
248
+ case 108:
249
+ _context2.next = 113;
250
+ break;
251
+ case 110:
252
+ _context2.prev = 110;
253
+ _context2.t2 = _context2["catch"](83);
254
+ _iterator3.e(_context2.t2);
255
+ case 113:
256
+ _context2.prev = 113;
257
+ _iterator3.f();
258
+ return _context2.finish(113);
259
+ case 116:
260
+ _context2.next = 118;
261
+ return connection.query("SHOW FULL TABLES IN `".concat(database, "` WHERE TABLE_TYPE LIKE 'VIEW'"));
262
+ case 118:
263
+ viewRows = _context2.sent;
264
+ _iterator4 = _createForOfIteratorHelper(viewRows);
265
+ _context2.prev = 120;
266
+ _iterator4.s();
267
+ case 122:
268
+ if ((_step4 = _iterator4.n()).done) {
269
+ _context2.next = 147;
270
+ break;
271
+ }
272
+ _row3 = _step4.value;
273
+ viewName = _row3["Tables_in_".concat(database.toLowerCase())];
274
+ if (!viewName) viewName = _row3["Tables_in_".concat(database)];
275
+ (0, _loggers.logger)("getting view Tables_in_".concat(database), viewName);
276
+ _context2.prev = 127;
277
+ _context2.next = 130;
278
+ return connection.query("SHOW CREATE VIEW `".concat(viewName, "`"));
279
+ case 130:
280
+ viewDefinition = _context2.sent;
281
+ views[viewName] = viewDefinition[0]['Create View'];
282
+ if (!(command === 'dump')) {
283
+ _context2.next = 139;
284
+ break;
285
+ }
286
+ _filePath2 = _path["default"].join(dbDir, 'views', "".concat(viewName, ".sql")); // Use the table directory for file saving
287
+ _context2.next = 136;
288
+ return _promises["default"].mkdir(_path["default"].dirname(_filePath2), {
289
+ recursive: true
290
+ });
291
+ case 136:
292
+ _context2.next = 138;
293
+ return _promises["default"].writeFile(_filePath2, "".concat(viewDefinition[0]['Create View'], "\n"), 'utf-8');
294
+ case 138:
295
+ (0, _loggers.logger)("View definition saved to: ".concat(_filePath2));
296
+ case 139:
297
+ _context2.next = 145;
298
+ break;
299
+ case 141:
300
+ _context2.prev = 141;
301
+ _context2.t3 = _context2["catch"](127);
302
+ (0, _loggers.logger)("Error retrieving definition for view ".concat(viewName, ":"), _context2.t3.message);
303
+ (0, _loggers.logger)(_row3);
304
+ case 145:
305
+ _context2.next = 122;
306
+ break;
307
+ case 147:
308
+ _context2.next = 152;
309
+ break;
310
+ case 149:
311
+ _context2.prev = 149;
312
+ _context2.t4 = _context2["catch"](120);
313
+ _iterator4.e(_context2.t4);
314
+ case 152:
315
+ _context2.prev = 152;
316
+ _iterator4.f();
317
+ return _context2.finish(152);
318
+ case 155:
319
+ return _context2.abrupt("return", {
320
+ tables: tables,
321
+ procedures: procedures,
322
+ views: views
323
+ });
324
+ case 156:
325
+ case "end":
326
+ return _context2.stop();
327
+ }
328
+ }, _callee2, null, [[17, 43, 46, 49], [53, 73, 76, 79], [83, 110, 113, 116], [120, 149, 152, 155], [127, 141]]);
329
+ }));
330
+ return function getDatabaseStructure(_x2, _x3, _x4, _x5) {
331
+ return _ref2.apply(this, arguments);
332
+ };
333
+ }();