pub struct LocalDb { /* private fields */ }Expand description
Local SQLite database shared by TUI and Daemon.
Thread-safe: wraps the connection in a Mutex so it can be shared via Arc<LocalDb>.
Implementations§
Source§impl LocalDb
impl LocalDb
Sourcepub fn open() -> Result<Self>
pub fn open() -> Result<Self>
Open (or create) the local database at the default path.
~/.local/share/opensession/local.db
Sourcepub fn open_path(path: &PathBuf) -> Result<Self>
pub fn open_path(path: &PathBuf) -> Result<Self>
Open (or create) the local database at a specific path.
pub fn upsert_local_session( &self, session: &Session, source_path: &str, git: &GitContext, ) -> Result<()>
pub fn upsert_remote_session(&self, summary: &SessionSummary) -> Result<()>
pub fn list_sessions( &self, filter: &LocalSessionFilter, ) -> Result<Vec<LocalSessionRow>>
Sourcepub fn list_sessions_log(
&self,
filter: &LogFilter,
) -> Result<Vec<LocalSessionRow>>
pub fn list_sessions_log( &self, filter: &LogFilter, ) -> Result<Vec<LocalSessionRow>>
Query sessions with extended filters for the log command.
Sourcepub fn get_sessions_by_tool_latest(
&self,
tool: &str,
count: u32,
) -> Result<Vec<LocalSessionRow>>
pub fn get_sessions_by_tool_latest( &self, tool: &str, count: u32, ) -> Result<Vec<LocalSessionRow>>
Get the latest N sessions for a specific tool, ordered by created_at DESC.
Sourcepub fn get_sessions_latest(&self, count: u32) -> Result<Vec<LocalSessionRow>>
pub fn get_sessions_latest(&self, count: u32) -> Result<Vec<LocalSessionRow>>
Get the latest N sessions across all tools, ordered by created_at DESC.
Sourcepub fn get_session_by_tool_offset(
&self,
tool: &str,
offset: u32,
) -> Result<Option<LocalSessionRow>>
pub fn get_session_by_tool_offset( &self, tool: &str, offset: u32, ) -> Result<Option<LocalSessionRow>>
Get the Nth most recent session for a specific tool (0 = HEAD, 1 = HEAD~1, etc.).
Sourcepub fn get_session_by_offset(
&self,
offset: u32,
) -> Result<Option<LocalSessionRow>>
pub fn get_session_by_offset( &self, offset: u32, ) -> Result<Option<LocalSessionRow>>
Get the Nth most recent session across all tools (0 = HEAD, 1 = HEAD~1, etc.).
Sourcepub fn session_count(&self) -> Result<i64>
pub fn session_count(&self) -> Result<i64>
Count total sessions in the local DB.
pub fn get_sync_cursor(&self, team_id: &str) -> Result<Option<String>>
pub fn set_sync_cursor(&self, team_id: &str, cursor: &str) -> Result<()>
Sourcepub fn pending_uploads(&self, team_id: &str) -> Result<Vec<LocalSessionRow>>
pub fn pending_uploads(&self, team_id: &str) -> Result<Vec<LocalSessionRow>>
Get sessions that are local_only and need to be uploaded.
pub fn mark_synced(&self, session_id: &str) -> Result<()>
Sourcepub fn was_uploaded_after(
&self,
source_path: &str,
modified: &DateTime<Utc>,
) -> Result<bool>
pub fn was_uploaded_after( &self, source_path: &str, modified: &DateTime<Utc>, ) -> Result<bool>
Check if a session was already uploaded (synced or remote_only) since the given modification time.
pub fn cache_body(&self, session_id: &str, body: &[u8]) -> Result<()>
pub fn get_cached_body(&self, session_id: &str) -> Result<Option<Vec<u8>>>
Sourcepub fn migrate_from_state_json(
&self,
uploaded: &HashMap<String, DateTime<Utc>>,
) -> Result<usize>
pub fn migrate_from_state_json( &self, uploaded: &HashMap<String, DateTime<Utc>>, ) -> Result<usize>
Migrate entries from the old state.json UploadState into the local DB.
Marks them as synced with no metadata (we only know the file path was uploaded).
Sourcepub fn link_commit_session(
&self,
commit_hash: &str,
session_id: &str,
repo_path: Option<&str>,
branch: Option<&str>,
) -> Result<()>
pub fn link_commit_session( &self, commit_hash: &str, session_id: &str, repo_path: Option<&str>, branch: Option<&str>, ) -> Result<()>
Link a git commit to an AI session.
Sourcepub fn get_sessions_by_commit(
&self,
commit_hash: &str,
) -> Result<Vec<LocalSessionRow>>
pub fn get_sessions_by_commit( &self, commit_hash: &str, ) -> Result<Vec<LocalSessionRow>>
Get all sessions linked to a git commit.
Sourcepub fn get_commits_by_session(
&self,
session_id: &str,
) -> Result<Vec<CommitLink>>
pub fn get_commits_by_session( &self, session_id: &str, ) -> Result<Vec<CommitLink>>
Get all commits linked to a session.
Sourcepub fn find_active_session_for_repo(
&self,
repo_path: &str,
since_minutes: u32,
) -> Result<Option<LocalSessionRow>>
pub fn find_active_session_for_repo( &self, repo_path: &str, since_minutes: u32, ) -> Result<Option<LocalSessionRow>>
Find the most recently active session for a given repo path.
“Active” means the session’s working_directory matches the repo path
and was created within the last since_minutes minutes.
Sourcepub fn list_repos(&self) -> Result<Vec<String>>
pub fn list_repos(&self) -> Result<Vec<String>>
Get a list of distinct git repo names present in the DB.