UNPKG

copybase

Version:

Copy or backup databases quickly

71 lines (70 loc) 3.41 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const BaseProvider_1 = __importDefault(require("./BaseProvider")); class MySQL extends BaseProvider_1.default { constructor(config) { super(Object.assign({ port: 3306 }, config)); } dump(outputFile) { return __awaiter(this, void 0, void 0, function* () { yield this.checkCommandExists("mysqldump", ["--version"]); const { database, hostname, port, username, password, mysqldump: mysqldumpOptions, } = this.config; const customOptions = this.getCustomOptions(mysqldumpOptions); this.logInfo(`Dump ${database}`); return this.execCommand("mysqldump", [ port ? `--port=${port}` : "", username ? `--user=${username}` : "", password ? `--password=${password}` : "", hostname ? `--host=${hostname}` : "", database, ...customOptions, `>${outputFile}`, ]); }); } restore(inputFile) { return __awaiter(this, void 0, void 0, function* () { yield this.checkCommandExists("mysql", ["--version"]); const { database, hostname, port, username, password, mysql: mysqlOptions, } = this.config; const customOptions = this.getCustomOptions(mysqlOptions); this.logInfo(`Restore ${database}`); return this.execCommand("mysql", [ port ? `--port=${port}` : "", username ? `--user=${username}` : "", password ? `--password=${password}` : "", hostname ? `--host=${hostname}` : "", ...customOptions, database, `<${inputFile}`, ]); }); } listTables() { return __awaiter(this, void 0, void 0, function* () { yield this.checkCommandExists("mysql", ["--version"]); const { database, hostname, port, username, password, mysql: mysqlOptions, } = this.config; const customOptions = this.getCustomOptions(mysqlOptions); return this.execCommand("mysql", [ port ? `--port=${port}` : "", username ? `--user=${username}` : "", password ? `--password=${password}` : "", hostname ? `--host=${hostname}` : "", ...customOptions, `--execute=SHOW TABLES FROM ${database};`, ], { env: { MYSQL_PWD: password } }); }); } } exports.default = MySQL;