2025-03-10 22:51:57 +01:00
|
|
|
const MySQLDatabase = require("./mysql");
|
|
|
|
const SQLiteDatabase = require("./sqlite");
|
|
|
|
|
2025-03-29 00:31:25 +01:00
|
|
|
let db;
|
|
|
|
|
|
|
|
async function connectDatabase(config) {
|
2025-03-10 22:51:57 +01:00
|
|
|
if (config.type === "mysql") {
|
2025-03-29 00:31:25 +01:00
|
|
|
db = new MySQLDatabase(config);
|
2025-03-10 22:51:57 +01:00
|
|
|
} else if (config.type === "sqlite") {
|
2025-03-29 00:31:25 +01:00
|
|
|
db = new SQLiteDatabase(config);
|
2025-03-10 22:51:57 +01:00
|
|
|
} else {
|
|
|
|
throw new Error("Invalid database type: ", config.type);
|
|
|
|
}
|
2025-03-29 00:31:25 +01:00
|
|
|
|
|
|
|
await db.connect();
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDatabase() {
|
|
|
|
return db;
|
2025-03-10 22:51:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-03-29 00:31:25 +01:00
|
|
|
module.exports = { getDatabase, connectDatabase };
|