mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-01-30 23:08:33 -06:00
Database connection can run in a thread, if you create a connection in a thread, then you have to use it only from that thread, moving it to another thread is disallowed. All restrictions for QSqlDatabase are true also for TinyORM. The most important work was in DatabaseManager because more threads can access it at once. DatabaseManager has to be created only once in the whole application, so it means when it will be created in a non-main thread, then it has to be used from this non-main thread the whole time, I didn't try it to move to another thread, the conclusion is that DatabaseManager can be created and used from a worker thread. - refactored db configuration - added DatabaseConnectionsMap to outsource ConnectionsType and make it thread_local - added resetDefaultConnection() - m_queryLogId is atomic - made all class static data members thread_local Thread unrelated: - added two new addConnections() overloads - added Thread utils class - added NameThreadForDebugging() - enhanced tst_DatabaseManager
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#pragma once
|
|
#ifndef ORM_CONNECTIONRESOLVERINTERFACE_HPP
|
|
#define ORM_CONNECTIONRESOLVERINTERFACE_HPP
|
|
|
|
#include "orm/macros/systemheader.hpp"
|
|
TINY_SYSTEM_HEADER
|
|
|
|
#include <QString>
|
|
|
|
#include "orm/macros/commonnamespace.hpp"
|
|
|
|
TINYORM_BEGIN_COMMON_NAMESPACE
|
|
|
|
namespace Orm
|
|
{
|
|
class ConnectionInterface;
|
|
|
|
/*! Database connection resolver interface. */
|
|
class ConnectionResolverInterface
|
|
{
|
|
public:
|
|
/*! Pure virtual destructor. */
|
|
inline virtual ~ConnectionResolverInterface() = 0;
|
|
|
|
/*! Get a database connection instance. */
|
|
virtual ConnectionInterface &connection(const QString &name = "") = 0;
|
|
|
|
/*! Get the default connection name. */
|
|
virtual const QString &getDefaultConnection() const = 0;
|
|
|
|
/*! Set the default connection name. */
|
|
virtual void setDefaultConnection(const QString &defaultConnection) = 0;
|
|
|
|
/*! Reset the default connection name to a default value. */
|
|
virtual void resetDefaultConnection() = 0;
|
|
};
|
|
|
|
ConnectionResolverInterface::~ConnectionResolverInterface() = default;
|
|
|
|
} // namespace Orm
|
|
|
|
TINYORM_END_COMMON_NAMESPACE
|
|
|
|
#endif // ORM_CONNECTIONRESOLVERINTERFACE_HPP
|