Refactor Database and File modules to improve data handling
Update the Database class to include explicit methods for fetching various entity types, managing relationships, and querying file paths. Implement hashing logic in the File module to facilitate tracking by unique identifiers. Add C++20 support in configuration files.
This commit is contained in:
@@ -34,6 +34,7 @@ struct Track {
|
||||
std::string artwork;
|
||||
TagLib::String genre;
|
||||
std::string format;
|
||||
uint64_t hash;
|
||||
};
|
||||
|
||||
using trackPtr = std::shared_ptr<Track>;
|
||||
|
||||
+19
-3
@@ -2,18 +2,34 @@
|
||||
|
||||
#include "Containers.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <sqlite3.h>
|
||||
|
||||
using queue = std::vector<Track>;
|
||||
|
||||
class Database {
|
||||
public:
|
||||
Database( const char* filename, sqlite3** db );
|
||||
Database( const char* filename );
|
||||
~Database();
|
||||
void fetch( const std::string& query ) const;
|
||||
void fetchAlbum( const std::string& album ) const;
|
||||
void fetchAll() const;
|
||||
void addTrack();
|
||||
void fetchAll( std::vector<Track>& entries ) const;
|
||||
void fetchAll( std::map<std::string, Track>& entries ) const;
|
||||
void fetchHashes( std::set<uint_fast64_t>& hashes );
|
||||
std::set<const char*> fetchFilePaths();
|
||||
std::optional<int> getArtistId( const std::string& artistName );
|
||||
std::optional<int> getAlbumId( const std::string& albumTitle );
|
||||
std::optional<int> getGenreId( const std::string& genre );
|
||||
void addTrack( Track t);
|
||||
void addArtist( const std::string& artistName );
|
||||
void addAlbum( Track t);
|
||||
void addGenre( std::string& genre );
|
||||
void setActive( bool active );
|
||||
void updateFilePath( const std::string& filePath );
|
||||
|
||||
sqlite3* getDb() { return db_; };
|
||||
private:
|
||||
sqlite3* db_;
|
||||
sqlite3_stmt* stmnt;
|
||||
|
||||
+3
-1
@@ -10,10 +10,12 @@ namespace fs = std::filesystem;
|
||||
|
||||
class File {
|
||||
public:
|
||||
void importFile( std::string fileName );
|
||||
Track importFile( const std::string& filePath );
|
||||
void importFolder( const std::string& folderPath, std::vector<Track>& tracks );
|
||||
void readFileTag( Track& t );
|
||||
std::string parseFiletype( const std::string& path );
|
||||
void updateLibrary();
|
||||
uint64_t hashString( Track t );
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
|
||||
Reference in New Issue
Block a user