mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-20 16:28:23 -05:00
tom throw if no conn. configuration registered
This commit is contained in:
@@ -244,6 +244,8 @@ namespace Concerns
|
||||
/*! Get database connection resolver. */
|
||||
std::shared_ptr<ConnectionResolverInterface> resolver() const noexcept;
|
||||
|
||||
/*! Throw if no connection configuration is registered. */
|
||||
void throwIfNoConnectionConfig() const;
|
||||
/*! Throw if a default connection is empty. */
|
||||
void throwIfEmptyDefaultConnection() const;
|
||||
|
||||
|
||||
@@ -159,6 +159,8 @@ Application::Application(int &argc, char **argv, std::shared_ptr<DatabaseManager
|
||||
|
||||
int Application::run()
|
||||
{
|
||||
// Throw if no database connection configuration is registered
|
||||
throwIfNoConnectionConfig();
|
||||
// Default database connection is required if exactly one connection is registered
|
||||
throwIfEmptyDefaultConnection();
|
||||
|
||||
@@ -653,6 +655,18 @@ std::shared_ptr<ConnectionResolverInterface> Application::resolver() const noexc
|
||||
return std::dynamic_pointer_cast<ConnectionResolverInterface>(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
|
||||
|
||||
Reference in New Issue
Block a user