mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-05 10:31:30 -06:00
28 lines
554 B
JavaScript
28 lines
554 B
JavaScript
import mysql from "mysql2";
|
|
|
|
export class Database {
|
|
constructor(config) {
|
|
this.connection = mysql.createConnection(config);
|
|
this.connection.connect();
|
|
}
|
|
|
|
query(sql, args) {
|
|
return new Promise((resolve, reject) => {
|
|
this.connection.query(sql, args, (err, rows) => {
|
|
if (err) return reject(err);
|
|
return resolve(rows);
|
|
});
|
|
});
|
|
}
|
|
|
|
close() {
|
|
this.connection.end((err) => {
|
|
if (err) {
|
|
console.error(err);
|
|
} else {
|
|
console.log("db connection closed");
|
|
}
|
|
});
|
|
}
|
|
}
|