UNPKG

agnostic-sql-migrator

Version:

Database agnostic migrator tool for SQL databases

41 lines 1.64 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const promise_1 = require("mysql2/promise"); const createClient = (config) => __awaiter(void 0, void 0, void 0, function* () { try { const client = yield promise_1.createConnection(Object.assign(Object.assign({}, config), { multipleStatements: true })); console.log('Successfully connected to MySQL DB'); return client; } catch (err) { throw err; } }); const query = (client, query) => __awaiter(void 0, void 0, void 0, function* () { const res = yield client.query(query); return res[0]; }); const closeConnection = (client) => __awaiter(void 0, void 0, void 0, function* () { try { yield client.end(); console.log('Connection to MySQL DB closed'); } catch (err) { throw err; } }); exports.default = { createClient, query, closeConnection, }; //# sourceMappingURL=index.js.map