From d713aeab8e60c4a471ecd046f8a5d1e7967beae6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 1 Dec 2020 15:01:02 +0100 Subject: [PATCH] Moved the db initialization code to a new header. --- database/db_init.h | 30 ++++++++++++++++++++++++++++++ main.cpp | 25 ++----------------------- 2 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 database/db_init.h diff --git a/database/db_init.h b/database/db_init.h new file mode 100644 index 0000000..c5cbd8c --- /dev/null +++ b/database/db_init.h @@ -0,0 +1,30 @@ +#ifndef DB_INIT_H +#define DB_INIT_H + +#if MYSQL_PRESENT +#include "mysql/mysql_database.h" +#endif + +#if PGSQL_PRESENT +#include "postgres/pgsql_database.h" +#endif + +#if SQLITE_PRESENT +#include "sqlite/sqlite3_database.h" +#endif + +void initialize_database_backends() { +#if MYSQL_PRESENT + MysqlDatabase::_register(); +#endif + +#if PGSQL_PRESENT + PGSQLDatabase::_register(); +#endif + +#if SQLITE_PRESENT + SQLite3Database::_register(); +#endif +} + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index b73a37b..c8c50b0 100644 --- a/main.cpp +++ b/main.cpp @@ -11,33 +11,12 @@ #include "core/database_manager.h" -#if MYSQL_PRESENT -#include "database/mysql/mysql_database.h" -#endif - -#if PGSQL_PRESENT -#include "database/postgres/pgsql_database.h" -#endif - -#if SQLITE_PRESENT -#include "database/sqlite/sqlite3_database.h" -#endif +#include "database/db_init.h" #define MAIN_CLASS RDNApplication int main(int argc, char **argv) { - -#if MYSQL_PRESENT - MysqlDatabase::_register(); -#endif - -#if PGSQL_PRESENT - PGSQLDatabase::_register(); -#endif - -#if SQLITE_PRESENT - SQLite3Database::_register(); -#endif + initialize_database_backends(); FileCache *file_cache = new FileCache(true); file_cache->wwwroot = "./www";