Files
ActivityPubD/source/db/db.d
2024-01-28 21:48:03 -03:00

51 lines
874 B
D

module db.db;
import slf4d;
import ddbc.core;
enum DBConnector {
DB_MYSQL,
DB_PGSQL,
DB_SQLITE,
}
struct DBSettings {
DBConnector connector;
string host;
ushort port;
string username;
string password;
string dbname;
}
class DB {
protected DBSettings m_settings;
protected DataSource m_ds;
protected Connection m_conn;
shared this(DBSettings settings) {
this.m_settings = settings;
}
static shared(DB) getDB(DBSettings settings) {
switch (settings.connector) {
case DBConnector.DB_PGSQL:
import db.pgsql;
debugF!"DB type is PostgreSQL";
return new shared PostgresDB(settings);
default:
throw new Exception("DB not supported");
}
}
protected abstract DataSource getDataSource();
void connect() {
this.m_ds = this.getDataSource();
this.m_conn = this.m_ds.getConnection();
}
}