ThreadedDatabase
#include <threadeddatabase.h>
Public Member Functions | |
template<typename ... Args> requires detail::isQVariantConvertible<Args...> | |
auto | execute (const QString &sqlQuery, Args... args) -> QFuture< void > |
template<typename T , typename ... Args> requires FromSql<T> && detail::isQVariantConvertible<Args...> | |
auto | getResult (const QString &sqlQuery, Args... args) -> QFuture< std::optional< T > > |
template<typename T , typename ... Args> requires FromSql<T> && detail::isQVariantConvertible<Args...> | |
auto | getResults (const QString &sqlQuery, Args... args) -> QFuture< std::vector< T > > |
auto | runMigrations (const QString &migrationDirectory) -> QFuture< void > |
template<typename Func > requires std::is_invocable_v<Func, const QSqlDatabase &> | |
auto | runOnThread (Func &&func) -> QFuture< std::invoke_result_t< Func, const QSqlDatabase & > > |
auto | setCurrentMigrationLevel (const QString &migrationName) -> QFuture< void > |
Public Member Functions inherited from QThread | |
QThread (QObject *parent) | |
virtual bool | event (QEvent *event) override |
QAbstractEventDispatcher * | eventDispatcher () const const |
void | exit (int returnCode) |
void | finished () |
bool | isFinished () const const |
bool | isInterruptionRequested () const const |
bool | isRunning () const const |
int | loopLevel () const const |
Priority | priority () const const |
void | quit () |
void | requestInterruption () |
void | setEventDispatcher (QAbstractEventDispatcher *eventDispatcher) |
void | setPriority (Priority priority) |
void | setStackSize (uint stackSize) |
uint | stackSize () const const |
void | start (Priority priority) |
void | started () |
void | terminate () |
bool | wait (QDeadlineTimer deadline) |
bool | wait (unsigned long time) |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QBindable< QString > | bindableObjectName () |
bool | blockSignals (bool block) |
const QObjectList & | children () const const |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectInfo () const const |
void | dumpObjectTree () const const |
QList< QByteArray > | dynamicPropertyNames () const const |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (Qt::FindChildOptions options) const const |
bool | inherits (const char *className) const const |
void | installEventFilter (QObject *filterObj) |
bool | isQuickItemType () const const |
bool | isWidgetType () const const |
bool | isWindowType () const const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
QVariant | property (const char *name) const const |
Q_CLASSINFO (Name, Value) | |
Q_EMIT Q_EMIT | |
Q_ENUM (...) | |
Q_ENUM_NS (...) | |
Q_ENUMS (...) | |
Q_FLAG (...) | |
Q_FLAG_NS (...) | |
Q_FLAGS (...) | |
Q_GADGET Q_GADGET | |
Q_GADGET_EXPORT (EXPORT_MACRO) | |
Q_INTERFACES (...) | |
Q_INVOKABLE Q_INVOKABLE | |
Q_MOC_INCLUDE Q_MOC_INCLUDE | |
Q_NAMESPACE Q_NAMESPACE | |
Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
Q_OBJECT Q_OBJECT | |
Q_PROPERTY (...) | |
Q_REVISION Q_REVISION | |
Q_SET_OBJECT_NAME (Object) | |
Q_SIGNAL Q_SIGNAL | |
Q_SIGNALS Q_SIGNALS | |
Q_SLOT Q_SLOT | |
Q_SLOTS Q_SLOTS | |
T | qobject_cast (const QObject *object) |
T | qobject_cast (QObject *object) |
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setObjectName (QAnyStringView name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | setProperty (const char *name, QVariant &&value) |
bool | signalsBlocked () const const |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType) |
QThread * | thread () const const |
Static Public Member Functions | |
static std::unique_ptr< ThreadedDatabase > | establishConnection (const DatabaseConfiguration &config) |
Static Public Member Functions inherited from QThread | |
QThread * | create (Function &&f, Args &&... args) |
QThread * | currentThread () |
Qt::HANDLE | currentThreadId () |
int | idealThreadCount () |
void | msleep (unsigned long msecs) |
void | sleep (std::chrono::nanoseconds nsecs) |
void | sleep (unsigned long secs) |
void | usleep (unsigned long usecs) |
void | yieldCurrentThread () |
Static Public Member Functions inherited from QObject | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
Additional Inherited Members | |
Public Types inherited from QThread | |
enum | Priority |
Public Types inherited from QObject | |
typedef | QObjectList |
Properties inherited from QObject | |
objectName | |
Public Attributes inherited from QThread | |
HighestPriority | |
HighPriority | |
IdlePriority | |
InheritPriority | |
LowestPriority | |
LowPriority | |
NormalPriority | |
TimeCriticalPriority | |
Protected Member Functions inherited from QThread | |
int | exec () |
virtual void | run () |
Protected Member Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
bool | isSignalConnected (const QMetaMethod &signal) const const |
int | receivers (const char *signal) const const |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Static Protected Member Functions inherited from QThread | |
void | setTerminationEnabled (bool enabled) |
Detailed Description
A database connection that lives on a new thread.
Definition at line 89 of file threadeddatabase.h.
Constructor & Destructor Documentation
◆ ~ThreadedDatabase()
ThreadedDatabase::~ThreadedDatabase | ( | ) |
Definition at line 355 of file threadeddatabase.cpp.
Member Function Documentation
◆ establishConnection()
|
static |
Connect to a database.
- Parameters
-
config Configuration of the database connection
- Returns
Definition at line 332 of file threadeddatabase.cpp.
◆ execute()
requires detail::isQVariantConvertible<Args...>
|
inline |
Execute an SQL query on the database, ignoring the result.
- Parameters
-
sqlQuery SQL query string to execute args Parameters to bind to the placeholders in the SQL Query
- Returns
Definition at line 106 of file threadeddatabase.h.
◆ getResult()
requires FromSql<T> && detail::isQVariantConvertible<Args...>
|
inline |
Like getResults, but for retrieving just one row.
- Parameters
-
sqlQuery SQL Query to execute args Parameters to bind to the placeholders in the SQL query.
Definition at line 156 of file threadeddatabase.h.
◆ getResults()
requires FromSql<T> && detail::isQVariantConvertible<Args...>
|
inline |
Execute an SQL query on the database, retrieving the result.
- Parameters
-
sqlQuery SQL Query to execute args Parameters to bind to the placeholders in the SQL query.
- Returns
- Future of a list of lists of variants.
T must provide a tuple of the column types as using ColumnTypes = std::tuple<...>
and a, if the column types are not the same types in the same order as the attributes of the struct, a static T fromSql(ColumnTypes tuple)
deserialization method.
Definition at line 145 of file threadeddatabase.h.
◆ runMigrations()
Run the database migrations in the given directory.
The directory needs to contain a subdirectory for each migration. The subdirectories need to be named so that when sorted alphabetically the migrations will be run in the correct order. Each subdirectory needs to contain a file named up.sql.
- Parameters
-
migrationDirectory Directory which contains the migrations.
- Returns
- a future that finishes when the database changes are finished
Definition at line 341 of file threadeddatabase.cpp.
◆ runOnThread()
requires std::is_invocable_v<Func, const QSqlDatabase &>
|
inline |
Run a custom function on the database thread.
The function is passed the internal QSqlDatabase.
- Parameters
-
func A function that takes a QSqlDatabase
- Returns
- The result of the function, wrapped in a QFuture
Definition at line 167 of file threadeddatabase.h.
◆ setCurrentMigrationLevel()
Declare that the database is currently at the state of the migration in the migration subdirectory migrationName.
The automatic migrations will then start with all migrations that are newer than migrationName.
- Warning
- This function should only be used for the initial switch from a different migration system, for example a custom made one.
- Parameters
-
migrationName
- Returns
- a future that finishes when the database changes are finished
Definition at line 345 of file threadeddatabase.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:14:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.