pub struct Database { /* private fields */ }Expand description
Database connection pool (simple Arc
Implementations§
Source§impl Database
impl Database
Sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>
Create a new database connection
§Arguments
path- Path to SQLite database file (or “:memory:” for in-memory)
Sourcepub fn initialize_schema(&self) -> Result<()>
pub fn initialize_schema(&self) -> Result<()>
Initialize database schema
Sourcepub fn create_conversation(
&self,
id: Uuid,
metadata: Option<String>,
) -> Result<()>
pub fn create_conversation( &self, id: Uuid, metadata: Option<String>, ) -> Result<()>
Create a new conversation
Sourcepub fn get_conversation(&self, id: Uuid) -> Result<Conversation>
pub fn get_conversation(&self, id: Uuid) -> Result<Conversation>
Get conversation by ID
Sourcepub fn end_conversation(&self, id: Uuid) -> Result<()>
pub fn end_conversation(&self, id: Uuid) -> Result<()>
End a conversation
Sourcepub fn increment_turn_count(&self, conversation_id: Uuid) -> Result<()>
pub fn increment_turn_count(&self, conversation_id: Uuid) -> Result<()>
Increment conversation turn count
Sourcepub fn store_event(
&self,
id: Uuid,
conversation_id: Uuid,
event_type: &str,
content: &str,
metadata: Option<String>,
) -> Result<()>
pub fn store_event( &self, id: Uuid, conversation_id: Uuid, event_type: &str, content: &str, metadata: Option<String>, ) -> Result<()>
Store an event
Sourcepub fn get_conversation_events(
&self,
conversation_id: Uuid,
) -> Result<Vec<StoredEvent>>
pub fn get_conversation_events( &self, conversation_id: Uuid, ) -> Result<Vec<StoredEvent>>
Get all events for a conversation
Sourcepub fn get_recent_events_by_type(
&self,
event_type: &str,
limit: usize,
) -> Result<Vec<StoredEvent>>
pub fn get_recent_events_by_type( &self, event_type: &str, limit: usize, ) -> Result<Vec<StoredEvent>>
Get recent events by type
Sourcepub fn delete_old_events(&self, before: DateTime<Utc>) -> Result<usize>
pub fn delete_old_events(&self, before: DateTime<Utc>) -> Result<usize>
Delete old events (for cleanup)
Sourcepub fn store_event_with_embedding(
&self,
id: Uuid,
conversation_id: Uuid,
event_type: &str,
content: &str,
metadata: Option<String>,
embedding: &[f32],
) -> Result<()>
pub fn store_event_with_embedding( &self, id: Uuid, conversation_id: Uuid, event_type: &str, content: &str, metadata: Option<String>, embedding: &[f32], ) -> Result<()>
Store an event with its embedding for conversation memory
Sourcepub fn search_conversation_history(
&self,
conversation_id: Uuid,
query_embedding: &[f32],
top_k: usize,
) -> Result<Vec<(StoredEvent, f32)>>
pub fn search_conversation_history( &self, conversation_id: Uuid, query_embedding: &[f32], top_k: usize, ) -> Result<Vec<(StoredEvent, f32)>>
Sourcepub fn get_stats(&self) -> Result<DatabaseStats>
pub fn get_stats(&self) -> Result<DatabaseStats>
Get database statistics
Source§impl Database
impl Database
Sourcepub fn conn(&self) -> Arc<Mutex<Connection>>
pub fn conn(&self) -> Arc<Mutex<Connection>>
Get a clone of the internal connection (for IdentityStore)
Sourcepub fn get_thought_count(&self) -> Result<usize>
pub fn get_thought_count(&self) -> Result<usize>
Get thought count from thoughtchain table
Sourcepub fn get_identity_count(&self) -> Result<usize>
pub fn get_identity_count(&self) -> Result<usize>
Get identity count from identities table
Sourcepub fn get_relationship_count(&self) -> Result<usize>
pub fn get_relationship_count(&self) -> Result<usize>
Get relationship count from relationships table
Sourcepub fn get_session_count(&self) -> Result<usize>
pub fn get_session_count(&self) -> Result<usize>
Get session count from sessions table
Sourcepub fn store_chat_message(
&self,
id: String,
instance_id: String,
role: String,
content: String,
timestamp: String,
) -> Result<()>
pub fn store_chat_message( &self, id: String, instance_id: String, role: String, content: String, timestamp: String, ) -> Result<()>
Store a chat message
Sourcepub fn get_chat_messages(
&self,
instance_id: &str,
limit: usize,
) -> Result<Vec<ChatMessage>>
pub fn get_chat_messages( &self, instance_id: &str, limit: usize, ) -> Result<Vec<ChatMessage>>
Get chat messages for a specific instance
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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