pub struct SqliteSession { /* private fields */ }Expand description
A Session implementation that uses SQLite for persistent storage.
SqliteSession provides a durable way to store conversation history,
making it ideal for applications that need to maintain state across
restarts. It uses sqlx for asynchronous database operations.
Implementations§
Source§impl SqliteSession
impl SqliteSession
Sourcepub async fn new(
session_id: impl Into<String>,
db_path: impl AsRef<Path>,
) -> Result<Self>
pub async fn new( session_id: impl Into<String>, db_path: impl AsRef<Path>, ) -> Result<Self>
Creates a new SqliteSession with a specific database file path.
This method establishes a connection pool to the SQLite database and runs migrations to ensure the necessary tables are created.
§Arguments
session_id- A unique identifier for the conversation session.db_path- The path to the SQLite database file.
Sourcepub async fn new_default(session_id: impl Into<String>) -> Result<Self>
pub async fn new_default(session_id: impl Into<String>) -> Result<Self>
Creates a new SqliteSession using the default database path “sessions.db”.
Sourcepub async fn new_in_memory(session_id: impl Into<String>) -> Result<Self>
pub async fn new_in_memory(session_id: impl Into<String>) -> Result<Self>
Creates an in-memory SqliteSession, useful for testing.
This version does not write to the filesystem, so the session data will be lost when the connection is closed.
Trait Implementations§
Source§impl Debug for SqliteSession
impl Debug for SqliteSession
Source§impl Session for SqliteSession
impl Session for SqliteSession
Source§fn session_id(&self) -> &str
fn session_id(&self) -> &str
Returns the unique identifier for the session.
Source§fn get_items<'life0, 'async_trait>(
&'life0 self,
limit: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Vec<RunItem>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_items<'life0, 'async_trait>(
&'life0 self,
limit: Option<usize>,
) -> Pin<Box<dyn Future<Output = Result<Vec<RunItem>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieves a list of
RunItems from the session.Source§fn add_items<'life0, 'async_trait>(
&'life0 self,
items: Vec<RunItem>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn add_items<'life0, 'async_trait>(
&'life0 self,
items: Vec<RunItem>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Adds a vector of
RunItems to the session.Source§fn pop_item<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<RunItem>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn pop_item<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<RunItem>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Removes and returns the most recent
RunItem from the session.Auto Trait Implementations§
impl Freeze for SqliteSession
impl !RefUnwindSafe for SqliteSession
impl Send for SqliteSession
impl Sync for SqliteSession
impl Unpin for SqliteSession
impl UnsafeUnpin for SqliteSession
impl !UnwindSafe for SqliteSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more