mrmBot-Matrix/utils/database.js
samhza ed25116851
Assorted db changes (#333)
* postgres: use transaction-scoped sql for upgrade

* database: combine fixGuild and addGuild into getGuild

* postgres, sqlite: simplify upgrade()

* allow running commands in DMs without prefix

this functionality was broken in
16095c0256 but is now fixed

* allow running esmBot without a database

Before this change, the only way to run esmBot without a database is to use the
dummy database driver which is broken but fails silently. THis can lead to a
confusing user experience. For instance, using `&command disable` with the
dummy database driver will tell you that the command has been disabled even
though it has not been.

This change adds support for running esmBot with no database driver by leaving
the DB= config option empty, and explicitly telling the user that some
functionality is now unavailable rather than failing silently like the dummy
driver.

* remove dummy database driver
2022-12-12 11:15:10 -06:00

20 lines
459 B
JavaScript

// wrapper for the database drivers in ./database/
import { config } from "dotenv";
config();
let db = null;
if (process.env.DB) {
const dbtype = process.env.DB.split("://")[0];
try {
db = await import(`./database/${dbtype}.js`);
} catch (error) {
if (error.code == "ERR_MODULE_NOT_FOUND") {
console.error(`DB config option has unknown database type '${dbtype}'`);
process.exit(1);
}
throw error;
}
}
export default db;