feat: initial database creation, loading

fixes for cartographer and automatically add track to album when adding to artist
This commit is contained in:
Joshua Strobl 2024-10-05 00:03:50 +03:00
parent 72bbcaba9e
commit 62c99ee67c
18 changed files with 515 additions and 108 deletions

View file

@ -1,3 +1,6 @@
#include <iostream>
#include "database.hpp"
#include "structs.hpp"
KotoAlbum::KotoAlbum() {
@ -5,8 +8,17 @@ KotoAlbum::KotoAlbum() {
this->tracks = QList<KotoTrack*>();
}
KotoAlbum* KotoAlbum::fromDb() {
return new KotoAlbum();
KotoAlbum* KotoAlbum::fromDb(const QSqlQuery& query, const QSqlRecord& record) {
KotoAlbum* album = new KotoAlbum();
album->uuid = QUuid {query.value(record.indexOf("id")).toString()};
album->artist_uuid = QUuid {query.value(record.indexOf("artist_id")).toString()};
album->title = QString {query.value(record.indexOf("name")).toString()};
album->year = query.value(record.indexOf("year")).toInt();
album->description = QString {query.value(record.indexOf("description")).toString()};
album->narrator = QString {query.value(record.indexOf("narrator")).toString()};
album->album_art_path = QString {query.value(record.indexOf("art_path")).toString()};
album->genres = QList {query.value(record.indexOf("genres")).toString().split(", ")};
return album;
}
KotoAlbum::~KotoAlbum() {
@ -18,6 +30,26 @@ void KotoAlbum::addTrack(KotoTrack* track) {
this->tracks.append(track);
}
void KotoAlbum::commit() {
QSqlQuery query(KotoDatabase::instance().getDatabase());
query.prepare(
"INSERT INTO albums(id, artist_id, name, description, narrator, art_path, genres, year) "
"VALUES (:id, :artist_id, :name, :description, :narrator, :art_path, :genres, :year) "
"ON CONFLICT(id) DO UPDATE SET artist_id = :artist_id, name = :name, description = :description, narrator = :narrator, art_path = "
":art_path, genres = :genres, year = :year");
query.bindValue(":id", this->uuid.toString());
query.bindValue(":artist_id", this->artist_uuid.toString());
query.bindValue(":name", this->title);
query.bindValue(":year", this->year.value_or(NULL));
query.bindValue(":description", this->description);
query.bindValue(":art_path", this->album_art_path);
query.bindValue(":narrator", this->narrator);
query.bindValue(":genres", this->genres.join(", "));
query.exec();
}
QString KotoAlbum::getAlbumArtPath() {
return QString {this->album_art_path};
}
@ -46,7 +78,7 @@ QList<KotoTrack*> KotoAlbum::getTracks() {
return QList {this->tracks};
}
int KotoAlbum::getYear() {
std::optional<int> KotoAlbum::getYear() {
return this->year;
}