Futuresql
FutureSQL
A non-blocking database framework for Qt.
FutureSQL was in part inspired by Diesel, and provides a higher level of abstraction than QtSql. Its features include non-blocking database access by default, relatively boilderplate-free queries, automatic database migrations and simple mapping to objects.
In order to make FutureSQL's use of templates less confusing, FutureSQL uses C++20 concepts, and requires a C++20 compiler.
Warning: The API is not finalized yet.
Usage
The following example demonstrates the usage of FutureSQL in conjunction with QCoro:
In code were coroutines don't make sense, you can use QCoro::connect
of QCoro > v0.8.0, or QFuture<T>::then()
on Qt6, to run a callback once a database query finished.
Migrations
FutureSQL can manage database migrations in a way that is mostly compatible with diesel. You just need to pass it a directory (preferably in QRC) that contains migrations in the following format:
Naming the migration directories after dates is a good practice, as the migrations are run in sorted order. Naming them for example by a counting number would break once the numbers get to large. For example, if you don't use leading zeros and only one digit, you'd only have up to 10 migrations.
The migration directory structure can be generated by the diesel
command line tool. You can install it using cargo as follows:
Finally, you can run the migrations from your C++ code:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:04:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.