Database

Struct Database 

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

Database connection wrapper with thread-safe access

Implementations§

Source§

impl Database

Source

pub fn new<P: AsRef<Path>>(path: P) -> Result<Self>

Create a new database connection and run migrations

§Arguments
  • path - Path to the SQLite database file
§Returns

A new Database instance

Source

pub fn insert_artifact(&self, artifact: &Artifact) -> Result<()>

Insert an artifact into the database

§Arguments
  • artifact - The artifact to insert
§Returns

Ok(()) if successful

Source

pub fn insert_spans(&self, spans: &[Span]) -> Result<()>

Insert multiple spans in a transaction

§Arguments
  • spans - Vector of spans to insert
§Returns

Ok(()) if successful

Source

pub fn get_vector_index(&self) -> Result<Arc<VectorIndex>>

Get or build the cached vector index

The index is cached and only rebuilt when data changes (on ingest). Phase 2.1: Tries to load from disk first, then builds if needed.

§Returns

A reference-counted vector index

Source

pub fn get_vector_index_with_kind( &self, ) -> Result<(Arc<VectorIndex>, IndexLoadKind)>

Get or build the cached vector index and return how it was obtained

Returns the index and an indicator of whether it was loaded from cache or freshly built from spans.

Source

pub fn get_all_spans(&self) -> Result<Vec<Span>>

Get all spans from the database

§Returns

Vector of all spans

Source

pub fn get_artifact(&self, artifact_id: &str) -> Result<Option<Artifact>>

Get artifact by ID

§Arguments
  • artifact_id - The artifact ID to look up
§Returns

The artifact if found

Source

pub fn get_artifact_by_path(&self, path: &str) -> Result<Option<Artifact>>

Get artifact by path

Returns the artifact row matching the unique path, if present.

Source

pub fn determine_ingest_action( &self, path: &str, content_hash: &str, ) -> Result<IngestAction>

Determine what action to take when ingesting a document

Compares content hash to detect if document needs update or can be skipped.

§Arguments
  • path - The document path
  • content_hash - SHA256 hash of the new content
§Returns
  • IngestAction::Skip if document exists with same content hash
  • IngestAction::Update if document exists but content changed
  • IngestAction::Create if document doesn’t exist
Source

pub fn delete_artifact(&self, artifact_id: &str) -> Result<usize>

Delete an artifact and its spans

§Arguments
  • artifact_id - The artifact ID to delete
§Returns

Number of spans deleted

Source

pub fn search_spans(&self, query: &str, limit: usize) -> Result<Vec<Span>>

Search spans by text content (simple keyword matching)

§Arguments
  • query - The search query
  • limit - Maximum number of results
§Returns

Vector of matching spans

Source

pub fn get_stats(&self) -> Result<(usize, usize, usize)>

Get database statistics

§Returns

(artifacts_count, spans_count, total_tokens)

Source

pub fn clear(&self) -> Result<()>

Clear all data from the database

Source

pub fn create_session( &self, user_id: Option<&str>, title: Option<&str>, ) -> Result<Session>

Create a new session

§Arguments
  • user_id - Optional user identifier
  • title - Optional session title
§Returns

The newly created session

Source

pub fn get_session(&self, session_id: &str) -> Result<Option<Session>>

Get a session by ID

§Arguments
  • session_id - The session ID to look up
§Returns

The session if found

Source

pub fn list_sessions( &self, user_id: Option<&str>, limit: Option<usize>, ) -> Result<Vec<Session>>

List sessions for a user (or all sessions if user_id is None)

§Arguments
  • user_id - Optional user ID to filter by
  • limit - Maximum number of sessions to return
§Returns

Vector of sessions, sorted by updated_at descending

Source

pub fn update_session( &self, session_id: &str, title: Option<&str>, metadata: Option<&Value>, ) -> Result<()>

Update session metadata

§Arguments
  • session_id - The session ID to update
  • title - Optional new title
  • metadata - Optional new metadata
§Returns

Ok(()) if successful

Source

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

Delete a session (cascades to messages and working sets)

§Arguments
  • session_id - The session ID to delete
§Returns

Ok(()) if successful

Source

pub fn add_message( &self, session_id: &str, role: MessageRole, content: &str, metadata: Option<&Value>, ) -> Result<Message>

Add a message to a session

§Arguments
  • session_id - The session to add the message to
  • role - Message role (user, assistant, system, tool)
  • content - Message content
  • metadata - Optional metadata
§Returns

The newly created message

Source

pub fn get_messages( &self, session_id: &str, limit: Option<usize>, ) -> Result<Vec<Message>>

Get messages for a session

§Arguments
  • session_id - The session ID
  • limit - Optional limit on number of messages (most recent first)
§Returns

Vector of messages in chronological order

Source

pub fn associate_working_set( &self, session_id: &str, message_id: Option<&str>, working_set: &WorkingSet, query: &str, config: &CompilerConfig, ) -> Result<SessionWorkingSet>

Associate a working set with a session

§Arguments
  • session_id - The session ID
  • message_id - Optional message ID that triggered this compilation
  • working_set - The working set to associate
  • query - Query that generated this working set
  • config - Configuration used for compilation
§Returns

The newly created SessionWorkingSet

Source

pub fn get_session_full( &self, session_id: &str, ) -> Result<Option<SessionWithMessages>>

Get session with all messages and working sets

§Arguments
  • session_id - The session ID
§Returns

SessionWithMessages if found

Trait Implementations§

Source§

impl Clone for Database

Source§

fn clone(&self) -> Database

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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