UNPKG

npxbase

Version:

A professional and modular database management library for Node.js with support for MySQL, PostgreSQL, and MongoDB.

28 lines (22 loc) 633 B
const mysql = require("mysql2/promise"); class MySQLAdapter { constructor() { this.connection = null; } async connect(config) { this.connection = await mysql.createConnection(config); console.log("Connected to MySQL"); } async disconnect() { if (this.connection) { await this.connection.end(); console.log("Disconnected from MySQL"); } } async query(sql, params) { if (!this.connection) throw new Error("No active MySQL connection"); const [rows] = await this.connection.execute(sql, params); return rows; } } module.exports = MySQLAdapter;