SqliteStorage

Struct SqliteStorage 

Source
pub struct SqliteStorage { /* private fields */ }
Expand description

SQLite-backed storage for mi6 events.

This struct provides the main entry point for database operations. It implements the Storage trait from mi6-core.

§Example

use mi6_storage_sqlite::SqliteStorage;
use mi6_core::Storage;

let storage = SqliteStorage::open(Path::new("events.db"))?;
let count = storage.count()?;

Implementations§

Source§

impl SqliteStorage

Source

pub fn open(path: &Path) -> Result<Self, StorageError>

Open or create a database at the given path.

This will:

  • Create the parent directory if needed
  • Enable WAL mode for better concurrent access
  • Set a busy timeout for handling concurrent writes
  • Initialize or migrate the schema as needed
Source

pub fn open_shared(path: &Path) -> Result<Arc<Self>, StorageError>

Open or create a database at the given path, wrapped in an Arc for shared ownership.

This is a convenience method equivalent to Arc::new(SqliteStorage::open(path)?). The returned Arc<SqliteStorage> implements the Storage trait directly, allowing you to use it anywhere a Storage implementation is expected.

§Thread Safety

Note: SqliteStorage itself is not Sync because rusqlite::Connection is not Sync. For true multi-threaded access, wrap in a Mutex:

use mi6_storage_sqlite::SqliteStorage;
use std::sync::{Arc, Mutex};

let storage = Arc::new(Mutex::new(SqliteStorage::open(path)?));

Or use a connection pool for high-concurrency scenarios.

§Example
use mi6_storage_sqlite::SqliteStorage;
use mi6_core::Storage;

let storage = SqliteStorage::open_shared(path)?;
// Arc<SqliteStorage> implements Storage, so you can call methods directly
let count = storage.count()?;
Source

pub fn query_transcript_positions( &self, ) -> Result<Vec<(String, FilePosition)>, StorageError>

Query all transcript file positions.

Returns a list of (file_path, position) pairs.

Trait Implementations§

Source§

impl Storage for SqliteStorage

Implement Storage trait for SqliteStorage.

Source§

fn insert(&self, event: &Event) -> Result<i64, StorageError>

Insert a new event, returns the event ID
Source§

fn query(&self, query: &EventQuery) -> Result<Vec<Event>, StorageError>

Query events using the composable EventQuery builder. Read more
Source§

fn gc(&self, retention: Duration) -> Result<usize, StorageError>

Delete events older than the retention period, returns count deleted.
Source§

fn count_expired(&self, retention: Duration) -> Result<usize, StorageError>

Count events older than the retention period (for dry-run).
Source§

fn count(&self) -> Result<usize, StorageError>

Count total events
Source§

fn list_sessions( &self, query: &SessionQuery, ) -> Result<Vec<Session>, StorageError>

List sessions matching the query criteria. Read more
Source§

fn get_session(&self, session_id: &str) -> Result<Option<Session>, StorageError>

Get a single session by ID. Read more
Source§

fn get_session_by_key( &self, machine_id: &str, session_id: &str, ) -> Result<Option<Session>, StorageError>

Get a single session by composite key (machine_id, session_id). Read more
Source§

fn get_session_by_pid(&self, pid: i32) -> Result<Option<Session>, StorageError>

Get a session by its process ID. Read more
Source§

fn update_session_git_info( &self, session_id: &str, git_info: &GitBranchInfo, ) -> Result<bool, StorageError>

Update git branch information for a session. Read more
Source§

fn storage_stats( &self, query: &StorageStatsQuery, ) -> Result<StorageStats, StorageError>

Get aggregated statistics across all sessions. Read more
Source§

fn get_transcript_position( &self, path: &Path, ) -> Result<Option<FilePosition>, StorageError>

Get the last scanned position for a transcript file. Read more
Source§

fn set_transcript_position( &self, path: &Path, position: &FilePosition, ) -> Result<(), StorageError>

Set the scanned position for a transcript file. Read more
Source§

fn event_exists_by_uuid( &self, session_id: &str, uuid: &str, ) -> Result<bool, StorageError>

Check if an event with the given UUID already exists for a session. Read more
Source§

fn query_transcript_positions( &self, ) -> Result<Vec<(String, FilePosition)>, StorageError>

Query all transcript file positions. Read more

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