pub struct Store { /* private fields */ }Expand description
Session-store handle.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, SessionError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, SessionError>
Open or create a database at path, running migrations.
§Errors
Returns a SessionError if the parent directory cannot be
created, the connection cannot be opened, or migrations fail.
Sourcepub fn open_in_memory() -> Result<Self, SessionError>
pub fn open_in_memory() -> Result<Self, SessionError>
In-memory store for tests.
§Errors
Returns a SessionError if the in-memory connection or
migrations fail.
Sourcepub fn start_session(
&self,
ulid: &str,
engine_base_url: Option<&str>,
cli_version: &str,
parent_ulid: Option<&str>,
) -> Result<i64, SessionError>
pub fn start_session( &self, ulid: &str, engine_base_url: Option<&str>, cli_version: &str, parent_ulid: Option<&str>, ) -> Result<i64, SessionError>
Start a new session. ulid should be freshly generated by
the caller (keeps this crate ulid-free) — any short unique
string works. Returns the row id for subsequent appends.
§Errors
Returns a SessionError::Sql on insert failure (e.g. ulid
collision).
Sourcepub fn end_session(&self, session_id: i64) -> Result<(), SessionError>
pub fn end_session(&self, session_id: i64) -> Result<(), SessionError>
Mark a session as ended. Idempotent — re-ending is a no-op.
§Errors
Propagates underlying SQL failures.
Sourcepub fn append(
&self,
session_id: i64,
kind: EventKind,
text: &str,
) -> Result<i64, SessionError>
pub fn append( &self, session_id: i64, kind: EventKind, text: &str, ) -> Result<i64, SessionError>
Append an event. The seq is allocated here so callers
don’t race on numbering. Returns the new seq.
§Errors
Propagates underlying SQL failures.
Sourcepub fn list_events(
&self,
session_id: i64,
limit: u32,
) -> Result<Vec<StoredEvent>, SessionError>
pub fn list_events( &self, session_id: i64, limit: u32, ) -> Result<Vec<StoredEvent>, SessionError>
List events in replay order, newest last. limit caps the
returned set from the tail (most recent limit entries).
§Errors
Propagates underlying SQL failures.
Sourcepub fn list_sessions(&self, limit: u32) -> Result<Vec<SessionRow>, SessionError>
pub fn list_sessions(&self, limit: u32) -> Result<Vec<SessionRow>, SessionError>
Fetch the N most recent sessions (by started_at desc).
limit == 0 returns an empty vec without hitting the DB.
Used by /sessions to paint a navigable list; the cli_version
and engine_base_url columns are pulled through so the listing
can show mismatches (e.g. an old session from a different
engine base URL) without a follow-up round-trip.
§Errors
Propagates underlying SQL failures.
Sourcepub fn get_session_by_ulid(
&self,
ulid: &str,
) -> Result<Option<SessionRow>, SessionError>
pub fn get_session_by_ulid( &self, ulid: &str, ) -> Result<Option<SessionRow>, SessionError>
Look up a session by its ulid. Returns None when no row
matches; Err only on SQL failure.
§Errors
Propagates underlying SQL failures.
Sourcepub fn count_events(&self, session_id: i64) -> Result<i64, SessionError>
pub fn count_events(&self, session_id: i64) -> Result<i64, SessionError>
Cheap COUNT(*) for a session’s events. Handy for the
/sessions list so it can render 42 event(s) without
pulling every row.
§Errors
Propagates underlying SQL failures.
Sourcepub fn last_session(&self) -> Result<Option<SessionRow>, SessionError>
pub fn last_session(&self) -> Result<Option<SessionRow>, SessionError>
Sourcepub fn set_milestone(&self, key: &str, value: &str) -> Result<(), SessionError>
pub fn set_milestone(&self, key: &str, value: &str) -> Result<(), SessionError>
Sourcepub fn get_milestone(&self, key: &str) -> Result<Option<String>, SessionError>
pub fn get_milestone(&self, key: &str) -> Result<Option<String>, SessionError>
Read a milestone. Returns None if it has never been set.
§Errors
Propagates underlying SQL failures.