Move backend name to config file

Still, only one backend is available at this point.
This commit is contained in:
King_DuckZ 2020-08-22 02:30:00 +01:00
parent c5e0b01b06
commit be1a19f7c7
6 changed files with 19 additions and 2 deletions

View file

@ -1,6 +1,7 @@
[system]
db_path=originsro.db3
worker_threads=3
backend=sqlite
[rules]
fetch_extra_delay=30

View file

@ -34,6 +34,9 @@ namespace {
constexpr const char g_worker_threads_sect[] = "system";
constexpr const char g_worker_threads[] = "worker_threads";
constexpr const char g_backend_sect[] = "system";
constexpr const char g_backend[] = "backend";
constexpr const char g_fetch_extra_delay_sect[] = "rules";
constexpr const char g_fetch_extra_delay[] = "fetch_extra_delay";
constexpr const char g_fetch_extra_delay_def[] = "30";
@ -125,4 +128,8 @@ std::size_t AppConfig::fetch_extra_delay() const {
}
}
std::string_view AppConfig::backend() const {
return value_ifp(m_ini, g_backend_sect, g_backend, g_def_backend_name, false);
}
} //namespace duck

View file

@ -32,6 +32,7 @@ public:
std::string_view api_key() const;
std::size_t worker_threads() const;
std::size_t fetch_extra_delay() const;
std::string_view backend() const;
private:
kamokan::IniFile m_ini;

View file

@ -31,4 +31,12 @@ constexpr const unsigned short int g_version_patch = @PROJECT_VERSION_PATCH@;
#mesondefine OROTOOL_WITH_SQLITE
#if defined(OROTOOL_WITH_SQLITE)
constexpr const char g_sqlite_backend_name[] = "sqlite";
#endif
#if defined(OROTOOL_WITH_SQLITE)
inline constexpr const auto& g_def_backend_name = g_sqlite_backend_name;
#endif
} //namespace duck

View file

@ -74,7 +74,7 @@ int main(int argc, char* argv[]) {
print_ping(oro_api);
std::unique_ptr<oro::OriginsDB> db(oro::OriginsDB::make("sqlite", app_conf.db_path()));
std::unique_ptr<oro::OriginsDB> db(oro::OriginsDB::make(app_conf.backend(), app_conf.db_path()));
duck::test(
&oro_api,

View file

@ -29,7 +29,7 @@ namespace oro {
return {};
}
#if defined(OROTOOL_WITH_SQLITE)
else if (name == "sqlite") {
else if (name == duck::g_sqlite_backend_name) {
return std::make_unique<OriginsDBSQLite>(param);
}
#endif