diff --git a/tom/include/tom/application.hpp b/tom/include/tom/application.hpp index 4df69c04e..9bd10c4db 100644 --- a/tom/include/tom/application.hpp +++ b/tom/include/tom/application.hpp @@ -244,6 +244,8 @@ namespace Concerns /*! Get database connection resolver. */ std::shared_ptr resolver() const noexcept; + /*! Throw if no connection configuration is registered. */ + void throwIfNoConnectionConfig() const; /*! Throw if a default connection is empty. */ void throwIfEmptyDefaultConnection() const; diff --git a/tom/src/tom/application.cpp b/tom/src/tom/application.cpp index d7a65a3df..c7984611c 100644 --- a/tom/src/tom/application.cpp +++ b/tom/src/tom/application.cpp @@ -159,6 +159,8 @@ Application::Application(int &argc, char **argv, std::shared_ptr Application::resolver() const noexc return std::dynamic_pointer_cast(m_db); } +void Application::throwIfNoConnectionConfig() const +{ + // Nothing to do, some database connection configuration/s are already registered + if (m_db->originalConfigsSize() > 0) + return; + + throw Exceptions::RuntimeError( + "No connection configuration is registered, please add at least one " + "database configuration to the DatabaseManager (eg. using " + "DB::create())."); +} + void Application::throwIfEmptyDefaultConnection() const { // Nothing to do, default connection is defined or more connections is registered