DatabaseManager.hpp 936 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <cstdint>
  5. #include <optional>
  6. #include <sqlite3.h>
  7. struct ImageData {
  8. int64_t id;
  9. std::string path;
  10. uint64_t dhash;
  11. uint64_t phash;
  12. int64_t timestamp;
  13. int64_t file_size;
  14. bool is_searched = false;
  15. };
  16. class DatabaseManager {
  17. public:
  18. DatabaseManager(const std::string& dbPath);
  19. ~DatabaseManager();
  20. bool open();
  21. void close();
  22. bool addImage(const ImageData& data);
  23. std::vector<ImageData> getAllImages();
  24. bool removeImage(const std::string& path);
  25. void cleanupStaleEntries();
  26. void beginTransaction();
  27. void commitTransaction();
  28. void rollbackTransaction();
  29. std::optional<ImageData> getImageByPath(const std::string& path);
  30. bool setDirectorySearchedStatus(const std::string& dirPath, bool isSearched);
  31. private:
  32. std::string m_dbPath;
  33. sqlite3* m_db = nullptr;
  34. bool initSchema();
  35. };