Compare commits

..
4 changed files with 44 additions and 36 deletions

No files matched your search

+41 -3
View File
@@ -10,6 +10,10 @@ class QSqlDatabase;
#include <QString>
#include <QObject>
#include <QFuture>
#include <QFutureWatcher>
#include <QSqlQuery>
#include <QDebug>
#include <QThread>
#include <QSharedDataPointer>
#include <memory>
@@ -19,6 +23,9 @@ class QSqlDatabase;
#include "asyncdatabase_p.h"
using Row = std::vector<QVariant>;
using Rows = std::vector<Row>;
struct DatabaseConfigurationPrivate;
///
@@ -59,6 +66,37 @@ private:
///
const QString DATABASE_TYPE_SQLITE = QStringLiteral("QSQLITE");
///
/// Parse the row into a tuple of the given types.
/// The types need to be deserializable from QVariant.
///
template <typename RowTypesTuple>
auto parseRow(const Row &row) -> RowTypesTuple
{
auto tuple = RowTypesTuple();
int i = 0;
asyncdatabase_private::iterate_tuple(tuple, [&](auto &elem) {
elem = row.at(i).value<std::decay_t<decltype(elem)>>();
i++;
});
return tuple;
}
///
/// Parse the rows into a list of tuples of the given types.
/// The types need to be deserializable from QVariant.
///
template <typename RowTypesTuple>
auto parseRows(const Rows &rows) -> std::vector<RowTypesTuple> {
std::vector<RowTypesTuple> parsedRows;
parsedRows.reserve(rows.size());
for (const auto &row : rows) {
parsedRows.push_back(parseRow<RowTypesTuple>(row));
}
return parsedRows;
}
template <typename T>
concept FromSql = requires(T v, typename T::ColumnTypes row)
{
@@ -85,7 +123,7 @@ public:
/// \return
///
template <typename ...Args>
requires std::conjunction_v<std::is_convertible<Args, QVariant>...>
requires std::conjunction_v<std::is_convertible<Args, Args>...>
auto execute(const QString &sqlQuery, Args... args) -> QFuture<void> {
return db().execute(sqlQuery, args...);
}
@@ -113,7 +151,7 @@ public:
/// and a `static T fromSql(ColumnTypes tuple)` deserialization method.
///
template <typename T, typename ...Args>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, QVariant>...>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, Args>...>
auto getResults(const QString &sqlQuery, Args... args) -> QFuture<std::vector<T>> {
return db().getResults<T, Args...>(sqlQuery, args...);
}
@@ -122,7 +160,7 @@ public:
/// \brief Like getResults, but for retrieving just one row.
///
template <typename T, typename ...Args>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, QVariant>...>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, Args>...>
auto getResult(const QString &sqlQuery, Args... args) -> QFuture<std::optional<T>> {
return db().getResult<T, Args...>(sqlQuery, args...);
}
-20
View File
@@ -60,26 +60,6 @@ void connectFuture(const QFuture<T> &future, QObjectDerivedType *self, const Fun
using Row = std::vector<QVariant>;
using Rows = std::vector<Row>;
template <typename RowTypesTuple>
auto parseRow(const Row &row) -> RowTypesTuple
{
auto tuple = RowTypesTuple();
int i = 0;
asyncdatabase_private::iterate_tuple(tuple, [&](auto &elem) {
elem = row.at(i).value<std::decay_t<decltype(elem)>>();
i++;
});
return tuple;
}
template <typename RowTypesTuple>
auto parseRows(const Rows &rows) -> std::vector<RowTypesTuple> {
std::vector<RowTypesTuple> parsedRows;
parsedRows.reserve(rows.size());
std::ranges::transform(rows, std::back_inserter(parsedRows), parseRow<RowTypesTuple>);
return parsedRows;
}
void runDatabaseMigrations(QSqlDatabase &database, const QString &migrationDirectory);
void printSqlError(const QSqlQuery &query);
+2 -2
View File
@@ -28,7 +28,7 @@ Item {
anchors.fill: parent
color: Qt.rgba(25, 25, 30, 1)
}
Image {
anchors.fill: parent
asynchronous: true
@@ -171,7 +171,7 @@ Item {
height: 512
}
fillMode: Image.PreserveAspectCrop
fillMode: Image.PreserveAspectFit
}
}
+1 -11
View File
@@ -65,8 +65,6 @@ Item {
Image {
id: mainIcon
anchors.fill: parent
visible: !loadingIndicator.visible
asynchronous: true
mipmap: true
@@ -74,15 +72,7 @@ Item {
sourceSize.width: 512
sourceSize.height: 512
fillMode: Image.PreserveAspectCrop
}
BusyIndicator {
id: loadingIndicator
anchors.centerIn: parent
visible: UserPlaylistModel.loading
Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
Kirigami.Theme.inherit: false
fillMode: Image.PreserveAspectFit
}
}