mirror of
https://github.com/silverqx/TinyORM.git
synced 2025-12-20 09:59:53 -06:00
added free methods to DatabaseManager, DB, Schema
[skip ci]
This commit is contained in:
@@ -149,6 +149,9 @@ namespace Query
|
||||
/*! Obtain a reference to the DatabaseManager. */
|
||||
static DatabaseManager &reference();
|
||||
|
||||
/*! Releases the ownership of the DatabaseManager managed object. */
|
||||
static void free() noexcept;
|
||||
|
||||
/*! Get a database connection instance. */
|
||||
DatabaseConnection &connection(const QString &name = "") final; // NOLINT(google-default-arguments)
|
||||
/*! Begin a fluent query against the database on a given connection (alias for
|
||||
|
||||
@@ -359,6 +359,10 @@ namespace Orm
|
||||
/*! Reset the number of executed queries on given connections. */
|
||||
static void resetStatementCounters(const QStringList &connections);
|
||||
|
||||
/* DB */
|
||||
/*! Releases the ownership of the DatabaseManager managed object. */
|
||||
static void free() noexcept;
|
||||
|
||||
private:
|
||||
/*! Get a reference to the DatabaseManager. */
|
||||
static DatabaseManager &manager();
|
||||
|
||||
@@ -103,6 +103,9 @@ namespace Orm
|
||||
const QString &connection = "");
|
||||
|
||||
/* Schema */
|
||||
/*! Releases the ownership of the DatabaseManager managed object. */
|
||||
static void free() noexcept;
|
||||
|
||||
/*! Get a schema builder instance for the default connection. */
|
||||
static SchemaBuilder &connection(const QString &name = "");
|
||||
/*! Get a schema builder instance for a connection. (alias for the connection()
|
||||
|
||||
@@ -292,6 +292,11 @@ DatabaseManager &DatabaseManager::reference()
|
||||
throw Exceptions::RuntimeError(InstanceExceptionMessage);
|
||||
}
|
||||
|
||||
void DatabaseManager::free() noexcept
|
||||
{
|
||||
m_instance.reset();
|
||||
}
|
||||
|
||||
DatabaseConnection &DatabaseManager::connection(const QString &name) // NOLINT(google-default-arguments)
|
||||
{
|
||||
const auto &connectionName = parseConnectionName(name);
|
||||
|
||||
@@ -628,6 +628,15 @@ void DB::resetStatementCounters(const QStringList &connections)
|
||||
manager().resetStatementCounters(connections);
|
||||
}
|
||||
|
||||
/* DB */
|
||||
|
||||
void DB::free() noexcept
|
||||
{
|
||||
// Reset both, DatabaseManager and DB ownership of the DatabaseManager managed object
|
||||
m_manager.reset();
|
||||
DatabaseManager::free();
|
||||
}
|
||||
|
||||
/* private */
|
||||
|
||||
DatabaseManager &DB::manager()
|
||||
|
||||
@@ -139,6 +139,11 @@ bool Schema::hasColumns(const QString &table, const QVector<QString> &columns,
|
||||
|
||||
/* Schema */
|
||||
|
||||
void Schema::free() noexcept
|
||||
{
|
||||
m_manager.reset();
|
||||
}
|
||||
|
||||
SchemaBuilder &Schema::connection(const QString &name)
|
||||
{
|
||||
return schemaBuilder(name);
|
||||
|
||||
@@ -83,6 +83,10 @@ private Q_SLOTS:
|
||||
void MySQL_addUseAndRemoveConnection_FiveTimes() const;
|
||||
void MySQL_addUseAndRemoveThreeConnections_FiveTimes() const;
|
||||
|
||||
// Can't be enabled (one time test only, run as needed)
|
||||
// void reset_DatabaseManager() const;
|
||||
// void reset_DB_DatabaseManager() const;
|
||||
|
||||
// NOLINTNEXTLINE(readability-redundant-access-specifiers)
|
||||
private:
|
||||
/*! Test case class name. */
|
||||
@@ -908,6 +912,32 @@ void tst_DatabaseManager::MySQL_addUseAndRemoveThreeConnections_FiveTimes() cons
|
||||
QVERIFY(m_dm->openedConnectionNames().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
/* These two tests can't be enabled as it resets the DatabaseManager::m_instance and
|
||||
destroys all connections and they can't be re-created easily. No need to invest
|
||||
more time to this and hack things around. */
|
||||
|
||||
//void tst_DatabaseManager::reset_DatabaseManager() const
|
||||
//{
|
||||
// // tst_DatabaseManager::m_dm, Databases::m_dm, and DatabaseManager::m_instance
|
||||
// QCOMPARE(m_dm.use_count(), 3);
|
||||
|
||||
// Orm::DatabaseManager::free();
|
||||
// QCOMPARE(m_dm.use_count(), 2);
|
||||
//}
|
||||
|
||||
//void tst_DatabaseManager::reset_DB_DatabaseManager() const
|
||||
//{
|
||||
// // tst_DatabaseManager::m_dm, Databases::m_dm, and DatabaseManager::m_instance
|
||||
// QCOMPARE(m_dm.use_count(), 3);
|
||||
|
||||
// // To assign/populate the DB::m_manager shared instance
|
||||
// Orm::DB::getDefaultConnection();
|
||||
// QCOMPARE(m_dm.use_count(), 4);
|
||||
|
||||
// Orm::DB::free();
|
||||
// QCOMPARE(m_dm.use_count(), 2);
|
||||
//}
|
||||
// NOLINTEND(readability-convert-member-functions-to-static)
|
||||
|
||||
/* private */
|
||||
|
||||
Reference in New Issue
Block a user