ThreadedDatabase

Search for usage in LXR

#include <threadeddatabase.h>

Inheritance diagram for ThreadedDatabase:

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
 
QAbstractEventDispatchereventDispatcher () 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< QStringbindableObjectName ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () 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< QByteArraydynamicPropertyNames () const const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
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 QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () 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
 
qobject_cast (const QObject *object)
 
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)
 
QThreadthread () const const
 

Static Public Member Functions

static std::unique_ptr< ThreadedDatabaseestablishConnection (const DatabaseConfiguration &config)
 
- Static Public Member Functions inherited from QThread
QThreadcreate (Function &&f, Args &&... args)
 
QThreadcurrentThread ()
 
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
 
QObjectsender () 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()

std::unique_ptr< ThreadedDatabase > ThreadedDatabase::establishConnection ( const DatabaseConfiguration & config)
static

Connect to a database.

Parameters
configConfiguration of the database connection
Returns

Definition at line 332 of file threadeddatabase.cpp.

◆ execute()

template<typename ... Args>
requires detail::isQVariantConvertible<Args...>
auto ThreadedDatabase::execute ( const QString & sqlQuery,
Args... args ) -> QFuture<void>
inline

Execute an SQL query on the database, ignoring the result.

Parameters
sqlQuerySQL query string to execute
argsParameters to bind to the placeholders in the SQL Query
Returns

Definition at line 106 of file threadeddatabase.h.

◆ getResult()

template<typename T , typename ... Args>
requires FromSql<T> && detail::isQVariantConvertible<Args...>
auto ThreadedDatabase::getResult ( const QString & sqlQuery,
Args... args ) -> QFuture<std::optional<T>>
inline

Like getResults, but for retrieving just one row.

Parameters
sqlQuerySQL Query to execute
argsParameters to bind to the placeholders in the SQL query.

Definition at line 156 of file threadeddatabase.h.

◆ getResults()

template<typename T , typename ... Args>
requires FromSql<T> && detail::isQVariantConvertible<Args...>
auto ThreadedDatabase::getResults ( const QString & sqlQuery,
Args... args ) -> QFuture<std::vector<T>>
inline

Execute an SQL query on the database, retrieving the result.

Parameters
sqlQuerySQL Query to execute
argsParameters 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()

auto ThreadedDatabase::runMigrations ( const QString & migrationDirectory) -> QFuture<void>

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
migrationDirectoryDirectory which contains the migrations.
Returns
a future that finishes when the database changes are finished

Definition at line 341 of file threadeddatabase.cpp.

◆ runOnThread()

template<typename Func >
requires std::is_invocable_v<Func, const QSqlDatabase &>
auto ThreadedDatabase::runOnThread ( Func && func) -> QFuture<std::invoke_result_t<Func, const QSqlDatabase &>>
inline

Run a custom function on the database thread.

The function is passed the internal QSqlDatabase.

Parameters
funcA function that takes a QSqlDatabase
Returns
The result of the function, wrapped in a QFuture

Definition at line 167 of file threadeddatabase.h.

◆ setCurrentMigrationLevel()

auto ThreadedDatabase::setCurrentMigrationLevel ( const QString & migrationName) -> QFuture<void>

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:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:50:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.