Skip to main content

Store

Struct Store 

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

Session-store handle.

Implementations§

Source§

impl Store

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn last_session(&self) -> Result<Option<SessionRow>, SessionError>

Fetch the most recent session (by started_at).

§Errors

Propagates underlying SQL failures.

Source

pub fn set_milestone(&self, key: &str, value: &str) -> Result<(), SessionError>

Set (upsert) a milestone flag.

§Errors

Propagates underlying SQL failures.

Source

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.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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.