Skip to main content

Database

Struct Database 

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

Core database wrapper

Implementations§

Source§

impl Database

Source

pub fn open(path: &str) -> Result<Self>

Source

pub fn open_existing_readonly(path: &str) -> Result<Option<Self>>

Open an existing database read-only. Returns Ok(None) when the file is missing so completion / debug paths never create whycodes.db.

Source

pub fn open_in_memory() -> Result<Self>

Source

pub fn upsert_session( &self, id: &str, title: &str, project_path: &str, created_at: &str, updated_at: &str, usage: &Usage, ) -> Result<()>

Insert or update a session row, preserving created_at on conflict.

Source

pub fn create_session( &self, id: &str, title: &str, project_path: &str, ) -> Result<()>

Convenience for tests / simple creates (zero usage, now timestamps).

Source

pub fn get_session(&self, id: &str) -> Result<Option<SessionRow>>

Source

pub fn list_sessions(&self) -> Result<Vec<SessionRow>>

Source

pub fn search_sessions_text( &self, terms: &[String], limit: usize, ) -> Result<Vec<SessionTextHit>>

Sessions with a message containing every term (ASCII case-insensitive), most recently updated first.

A scan rather than an FTS index: every save rewrites a session’s messages, and an index made a 500-message save ~15x slower, while a scan of a 120k-message database takes ~0.3 s at search time only.

Source

pub fn usage_totals(&self) -> Result<UsageTotals>

Sum provider-reported usage and message counts across all sessions.

Source

pub fn update_title(&self, id: &str, title: &str) -> Result<()>

Source

pub fn delete_session(&self, id: &str) -> Result<()>

Source

pub fn insert_message( &self, msg_id: &str, session_id: &str, role: &str, content: &str, tool_call_id: Option<&str>, name: Option<&str>, ) -> Result<()>

Source

pub fn delete_messages(&self, session_id: &str) -> Result<()>

Drop all messages for a session (used before full re-persist).

Source

pub fn replace_messages( &self, session_id: &str, messages: &[MessageInsert], ) -> Result<()>

Replace every message for a session in one transaction.

Full rewrite keeps the table honest across multi-turn persists; the transaction avoids half-written transcripts if a process dies mid-loop.

Source

pub fn replace_transcript( &self, session_id: &str, messages: &[MessageInsert], branches: &[BranchInsert], ) -> Result<()>

Replace the active path and every stored branch of a session in one transaction, so a crash mid-save never leaves a switched-away path unsaved: the old rows stay until the new ones commit.

Source

pub fn get_branches(&self, session_id: &str) -> Result<Vec<BranchRow>>

Stored branches of a session in save order. A session saved before branches existed has none. Message rows whose branch header is missing still come back, as an unnamed branch, rather than being dropped.

Source

pub fn message_counts_by_session(&self) -> Result<HashMap<String, usize>>

Message counts for every session in one query (session picker).

Source

pub fn get_messages(&self, session_id: &str) -> Result<Vec<MessageRow>>

Source

pub fn message_count(&self, session_id: &str) -> Result<usize>

Source

pub fn get_state(&self, key: &str) -> Result<Option<String>>

Source

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

Source

pub fn delete_state(&self, key: &str) -> Result<()>

Source

pub fn insert_memory( &self, id: &str, project_key: &str, text: &str, embedding: &[u8], source_session: Option<&str>, ) -> Result<()>

Source

pub fn get_memory(&self, id: &str) -> Result<Option<MemoryRow>>

Source

pub fn list_memories( &self, project_key: &str, limit: usize, ) -> Result<Vec<MemoryRow>>

Source

pub fn delete_memory(&self, id: &str) -> Result<bool>

Source

pub fn clear_memories(&self, project_key: &str) -> Result<usize>

Source

pub fn touch_memory_recall(&self, id: &str) -> Result<()>

Source

pub fn count_memories(&self, project_key: &str) -> Result<usize>

Source

pub fn insert_code_chunk( &self, id: &str, project_key: &str, path: &str, start_line: i64, end_line: i64, text: &str, embedding: &[u8], ) -> Result<()>

Source

pub fn list_code_chunks( &self, project_key: &str, limit: usize, ) -> Result<Vec<CodeChunkRow>>

Source

pub fn clear_code_chunks(&self, project_key: &str) -> Result<usize>

Source

pub fn insert_session_chunk( &self, id: &str, project_key: &str, session_id: &str, turn_index: i64, text: &str, embedding: &[u8], ) -> Result<()>

Source

pub fn list_session_chunks( &self, project_key: &str, limit: usize, ) -> Result<Vec<SessionChunkRow>>

Source

pub fn search_memories( &self, project_key: &str, query: &str, limit: usize, ) -> Result<FtsPage<MemoryRow>>

Up to limit facts that share a word with query, best BM25 first.

Source

pub fn search_code_chunks( &self, project_key: &str, query: &str, limit: usize, ) -> Result<FtsPage<CodeChunkRow>>

Up to limit code chunks that share a word with query.

Source

pub fn search_session_chunks( &self, project_key: &str, query: &str, limit: usize, ) -> Result<FtsPage<SessionChunkRow>>

Up to limit past session turns that share a word with query.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more