28#include <unordered_map>
131 bool open(
const std::string& path);
193 std::optional<Game>
getGame(
const std::string& gameId)
const;
200 bool gameExists(
const std::string& gameId)
const;
216 int offset = 0)
const;
229 int getGameCount(
const DatabaseFilterOptions& filter = {})
const;
237 std::vector<Game>
searchGames(
const std::string& query,
int limit = 50)
const;
292 int importFromJson(
const std::string& path,
bool overwriteExisting =
false);
348 const std::string& protonVersion =
"");
356 bool endSession(int64_t sessionId,
const std::string& exitReason =
"normal");
364 std::vector<PlaySession>
getRecentSessions(
const std::string& gameId,
int limit = 20)
const;
377 const std::string& protonVersion =
"",
const std::string& errorMessage =
"",
378 int timeToLaunchMs = 0);
398 int64_t
getTotalPlaytime(
const std::string& startDate,
const std::string& endDate)
const;
407 std::vector<std::pair<std::string, int64_t>>
getPlaytimeByGame(
const std::string& startDate,
408 const std::string& endDate,
409 int limit = 10)
const;
417 std::vector<std::pair<std::string, int64_t>>
getPlaytimeByDay(
const std::string& startDate,
418 const std::string& endDate)
const;
424 std::vector<std::pair<GameRunner, int64_t>>
getRunnerStats()
const;
468 bool runMigrations(
int fromVersion);
471 bool executeSQL(
const std::string& sql);
472 Game gameFromStatement(sqlite3_stmt* stmt)
const;
477 enum class SchemaVersionState
484 struct SchemaVersionResult
486 SchemaVersionState state;
489 SchemaVersionResult getSchemaVersionInternal()
const;
492 bool addGameToCollectionInternal(
const std::string& gameId,
const std::string& collection);
493 bool removeGameFromCollectionInternal(
const std::string& gameId,
const std::string& collection);
496 sqlite3* db_ =
nullptr;
497 mutable std::recursive_mutex mutex_;
498 mutable std::string lastError_;
507 mutable std::unordered_map<std::string, sqlite3_stmt*> stmtCache_;
508 sqlite3_stmt* getCachedStatement(
const char* sql)
const;
509 void clearStatementCache();
514 static constexpr int SCHEMA_VERSION = 5;
std::vector< Game > queryGames(const DatabaseFilterOptions &filter={}, const DatabaseSortOptions &sort={}, int limit=0, int offset=0) const
Query games with filtering and sorting.
std::vector< std::pair< GameSource, int > > getSourceStats() const
Get source statistics (games per source).
bool updateGame(const Game &game)
Update an existing game.
bool updateDailyPlaytime(const std::string &gameId, int playTimeSeconds)
Update daily playtime aggregation.
std::vector< Game > searchGames(const std::string &query, int limit=50) const
Search games by name (uses FTS if available).
std::vector< std::pair< std::string, int64_t > > getPlaytimeByDay(const std::string &startDate, const std::string &endDate) const
Get playtime by day for a date range.
bool removeGameFromCollection(const std::string &gameId, const std::string &collection)
Remove game from collection.
void close()
Close the database.
std::optional< Game > getGame(const std::string &gameId) const
Get a game by ID.
bool exportToJson(const std::string &path) const
Export all games to JSON.
bool insertGame(const Game &game)
Insert a new game.
GameDatabase(const GameDatabase &)=delete
bool isOpen() const
Check if database is open.
int64_t getTotalPlaytime(const std::string &startDate, const std::string &endDate) const
Get total playtime for a specific date range.
bool commitTransaction()
Commit current transaction.
bool addCollection(const std::string &name)
Add a collection.
bool deleteGame(const std::string &gameId)
Delete a game by ID.
bool vacuum()
Vacuum database to reclaim space.
bool recordLaunch(const std::string &gameId, bool success, GameRunner runner, const std::string &protonVersion="", const std::string &errorMessage="", int timeToLaunchMs=0)
Record a launch attempt (success or failure).
bool addGameToCollection(const std::string &gameId, const std::string &collection)
Add game to collection.
int importFromJson(const std::string &path, bool overwriteExisting=false)
Import games from JSON.
bool beginTransaction()
Begin a transaction.
bool withTransaction(const std::function< bool()> &func)
Execute a function within a transaction.
std::vector< Game > getRecentlyPlayedGames(int limit=10) const
Get recently played games.
bool open(const std::string &path)
Open or create the database.
std::vector< Game > getMostPlayedGames(int limit=10) const
Get most played games.
std::vector< std::pair< GameRunner, int64_t > > getRunnerStats() const
Get runner usage statistics.
int64_t startSession(const std::string &gameId, GameRunner runner, const std::string &protonVersion="")
Record a game session start.
bool endSession(int64_t sessionId, const std::string &exitReason="normal")
End a game session.
std::pair< int, int > getGameCrashStats(const std::string &gameId) const
Get crash statistics for a game.
bool gameExists(const std::string &gameId) const
Check if a game exists.
std::vector< PlaySession > getRecentSessions(const std::string &gameId, int limit=20) const
Get recent play sessions for a game.
std::vector< std::string > getCollections() const
Get all collection names.
std::vector< Game > getGamesWithoutCoverArt(int limit=0) const
Get games that are missing cover art.
bool updateGameImages(const std::string &gameId, const GameImagePaths &images)
Update only the image paths for a game (efficient partial update).
double getAverageSessionDuration(const std::string &gameId) const
Get average session duration for a game.
std::vector< Game > getAllGames() const
Get all games (convenience method).
std::string lastError() const
Get last error message.
bool rollbackTransaction()
Rollback current transaction.
int getSchemaVersion() const
Get database schema version.
std::vector< std::pair< std::string, int64_t > > getPlaytimeByGame(const std::string &startDate, const std::string &endDate, int limit=10) const
Get playtime by game for a date range.
bool removeCollection(const std::string &name)
Remove a collection.
int getGameCount(const DatabaseFilterOptions &filter={}) const
Get total game count.
GameDatabase & operator=(const GameDatabase &)=delete
Complete representation of a game in the library.
GameRunner
Runner/compatibility layer for executing the game.
Filter options for database queries.
std::optional< GameSource > sourceFilter
std::optional< GameRunner > runnerFilter
Sort options for database queries.
Paths to various game image assets.
@ Game
Game-specific fixes.