Skip to main content

LocalDb

Struct LocalDb 

Source
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

Source

pub fn open() -> Result<Self>

Open (or create) the local database at the default path. ~/.local/share/opensession/local.db

Source

pub fn open_path(path: &PathBuf) -> Result<Self>

Open (or create) the local database at a specific path.

Source

pub fn upsert_local_session( &self, session: &Session, source_path: &str, git: &GitContext, ) -> Result<()>

Source

pub fn upsert_remote_session(&self, summary: &SessionSummary) -> Result<()>

Source

pub fn list_sessions( &self, filter: &LocalSessionFilter, ) -> Result<Vec<LocalSessionRow>>

Source

pub fn list_sessions_log( &self, filter: &LogFilter, ) -> Result<Vec<LocalSessionRow>>

Query sessions with extended filters for the log command.

Source

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.

Source

pub fn get_sessions_latest(&self, count: u32) -> Result<Vec<LocalSessionRow>>

Get the latest N sessions across all tools, ordered by created_at DESC.

Source

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.).

Source

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.).

Source

pub fn session_count(&self) -> Result<i64>

Count total sessions in the local DB.

Source

pub fn get_sync_cursor(&self, team_id: &str) -> Result<Option<String>>

Source

pub fn set_sync_cursor(&self, team_id: &str, cursor: &str) -> Result<()>

Source

pub fn pending_uploads(&self, team_id: &str) -> Result<Vec<LocalSessionRow>>

Get sessions that are local_only and need to be uploaded.

Source

pub fn mark_synced(&self, session_id: &str) -> Result<()>

Source

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.

Source

pub fn cache_body(&self, session_id: &str, body: &[u8]) -> Result<()>

Source

pub fn get_cached_body(&self, session_id: &str) -> Result<Option<Vec<u8>>>

Source

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).

Link a git commit to an AI session.

Source

pub fn get_sessions_by_commit( &self, commit_hash: &str, ) -> Result<Vec<LocalSessionRow>>

Get all sessions linked to a git commit.

Source

pub fn get_commits_by_session( &self, session_id: &str, ) -> Result<Vec<CommitLink>>

Get all commits linked to a session.

Source

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.

Source

pub fn list_repos(&self) -> Result<Vec<String>>

Get a list of distinct git repo names present in the DB.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.