Skip to main content

SqliteStore

Struct SqliteStore 

Source
pub struct SqliteStore { /* private fields */ }

Implementations§

Source§

impl SqliteStore

Source

pub async fn load_input_history( &self, limit: i64, ) -> Result<Vec<String>, MemoryError>

Load the most recent input history entries, ordered chronologically.

§Errors

Returns an error if the query fails.

Source

pub async fn save_input_entry(&self, text: &str) -> Result<(), MemoryError>

Persist a new input history entry.

§Errors

Returns an error if the insert fails.

Source

pub async fn clear_input_history(&self) -> Result<(), MemoryError>

Delete all input history entries.

§Errors

Returns an error if the delete fails.

Source§

impl SqliteStore

Source

pub async fn create_conversation(&self) -> Result<ConversationId, MemoryError>

Create a new conversation and return its ID.

§Errors

Returns an error if the insert fails.

Source

pub async fn save_message( &self, conversation_id: ConversationId, role: &str, content: &str, ) -> Result<MessageId, MemoryError>

Save a message to the given conversation and return the message ID.

§Errors

Returns an error if the insert fails.

Source

pub async fn save_message_with_parts( &self, conversation_id: ConversationId, role: &str, content: &str, parts_json: &str, ) -> Result<MessageId, MemoryError>

Save a message with structured parts JSON.

§Errors

Returns an error if the insert fails.

Source

pub async fn load_history( &self, conversation_id: ConversationId, limit: u32, ) -> Result<Vec<Message>, MemoryError>

Load the most recent messages for a conversation, up to limit.

§Errors

Returns an error if the query fails.

Source

pub async fn latest_conversation_id( &self, ) -> Result<Option<ConversationId>, MemoryError>

Return the ID of the most recent conversation, if any.

§Errors

Returns an error if the query fails.

Source

pub async fn message_by_id( &self, message_id: MessageId, ) -> Result<Option<Message>, MemoryError>

Fetch a single message by its ID.

§Errors

Returns an error if the query fails.

Source

pub async fn messages_by_ids( &self, ids: &[MessageId], ) -> Result<Vec<(MessageId, Message)>, MemoryError>

Fetch messages by a list of IDs in a single query.

§Errors

Returns an error if the query fails.

Source

pub async fn unembedded_message_ids( &self, limit: Option<usize>, ) -> Result<Vec<(MessageId, ConversationId, String, String)>, MemoryError>

Return message IDs and content for messages without embeddings.

§Errors

Returns an error if the query fails.

Source

pub async fn count_messages( &self, conversation_id: ConversationId, ) -> Result<i64, MemoryError>

Count the number of messages in a conversation.

§Errors

Returns an error if the query fails.

Source

pub async fn count_messages_after( &self, conversation_id: ConversationId, after_id: MessageId, ) -> Result<i64, MemoryError>

Count messages in a conversation with id greater than after_id.

§Errors

Returns an error if the query fails.

Full-text keyword search over messages using FTS5.

Returns message IDs with BM25 relevance scores (lower = more relevant, negated to positive for consistency with vector scores).

§Errors

Returns an error if the query fails.

Source

pub async fn load_messages_range( &self, conversation_id: ConversationId, after_message_id: MessageId, limit: usize, ) -> Result<Vec<(MessageId, String, String)>, MemoryError>

Load a range of messages after a given message ID.

§Errors

Returns an error if the query fails.

Source§

impl SqliteStore

Source

pub async fn record_skill_usage( &self, skill_names: &[&str], ) -> Result<(), MemoryError>

Record usage of skills (UPSERT: increment count and update timestamp).

§Errors

Returns an error if the database operation fails.

Source

pub async fn load_skill_usage(&self) -> Result<Vec<SkillUsageRow>, MemoryError>

Load all skill usage statistics.

§Errors

Returns an error if the query fails.

Source

pub async fn record_skill_outcome( &self, skill_name: &str, version_id: Option<i64>, conversation_id: Option<ConversationId>, outcome: &str, error_context: Option<&str>, ) -> Result<(), MemoryError>

Record a skill outcome event.

§Errors

Returns an error if the insert fails.

Source

pub async fn record_skill_outcomes_batch( &self, skill_names: &[String], conversation_id: Option<ConversationId>, outcome: &str, error_context: Option<&str>, ) -> Result<(), MemoryError>

Record outcomes for multiple skills in a single transaction.

§Errors

Returns an error if any insert fails (whole batch is rolled back).

Source

pub async fn skill_metrics( &self, skill_name: &str, ) -> Result<Option<SkillMetricsRow>, MemoryError>

Load metrics for a skill (latest version group).

§Errors

Returns an error if the query fails.

Source

pub async fn load_skill_outcome_stats( &self, ) -> Result<Vec<SkillMetricsRow>, MemoryError>

Load all skill outcome stats grouped by skill name.

§Errors

Returns an error if the query fails.

Source

pub async fn save_skill_version( &self, skill_name: &str, version: i64, body: &str, description: &str, source: &str, error_context: Option<&str>, predecessor_id: Option<i64>, ) -> Result<i64, MemoryError>

Save a new skill version and return its ID.

§Errors

Returns an error if the insert fails.

Source

pub async fn active_skill_version( &self, skill_name: &str, ) -> Result<Option<SkillVersionRow>, MemoryError>

Load the active version for a skill.

§Errors

Returns an error if the query fails.

Source

pub async fn activate_skill_version( &self, skill_name: &str, version_id: i64, ) -> Result<(), MemoryError>

Activate a specific version (deactivates others for the same skill).

§Errors

Returns an error if the update fails.

Source

pub async fn next_skill_version( &self, skill_name: &str, ) -> Result<i64, MemoryError>

Get the next version number for a skill.

§Errors

Returns an error if the query fails.

Source

pub async fn last_improvement_time( &self, skill_name: &str, ) -> Result<Option<String>, MemoryError>

Get the latest auto-generated version’s created_at for cooldown check.

§Errors

Returns an error if the query fails.

Source

pub async fn ensure_skill_version_exists( &self, skill_name: &str, body: &str, description: &str, ) -> Result<(), MemoryError>

Ensure a base (v1 manual) version exists for a skill. Idempotent.

§Errors

Returns an error if the DB operation fails.

Source

pub async fn load_skill_versions( &self, skill_name: &str, ) -> Result<Vec<SkillVersionRow>, MemoryError>

Load all versions for a skill, ordered by version number.

§Errors

Returns an error if the query fails.

Source

pub async fn count_auto_versions( &self, skill_name: &str, ) -> Result<i64, MemoryError>

Count auto-generated versions for a skill.

§Errors

Returns an error if the query fails.

Source

pub async fn prune_skill_versions( &self, skill_name: &str, max_versions: u32, ) -> Result<u32, MemoryError>

Delete oldest non-active auto versions exceeding max limit. Returns the number of pruned versions.

§Errors

Returns an error if the delete fails.

Source

pub async fn predecessor_version( &self, version_id: i64, ) -> Result<Option<SkillVersionRow>, MemoryError>

Get the predecessor version for rollback.

§Errors

Returns an error if the query fails.

Source§

impl SqliteStore

Source

pub async fn save_summary( &self, conversation_id: ConversationId, content: &str, first_message_id: MessageId, last_message_id: MessageId, token_estimate: i64, ) -> Result<i64, MemoryError>

Save a summary and return its ID.

§Errors

Returns an error if the insert fails.

Source

pub async fn load_summaries( &self, conversation_id: ConversationId, ) -> Result<Vec<(i64, ConversationId, String, MessageId, MessageId, i64)>, MemoryError>

Load all summaries for a conversation.

§Errors

Returns an error if the query fails.

Source

pub async fn latest_summary_last_message_id( &self, conversation_id: ConversationId, ) -> Result<Option<MessageId>, MemoryError>

Get the last message ID covered by the most recent summary.

§Errors

Returns an error if the query fails.

Source§

impl SqliteStore

Source

pub async fn upsert_skill_trust( &self, skill_name: &str, trust_level: &str, source_kind: &str, source_url: Option<&str>, source_path: Option<&str>, blake3_hash: &str, ) -> Result<(), MemoryError>

Upsert trust metadata for a skill.

§Errors

Returns an error if the database operation fails.

Source

pub async fn load_skill_trust( &self, skill_name: &str, ) -> Result<Option<SkillTrustRow>, MemoryError>

Load trust metadata for a single skill.

§Errors

Returns an error if the query fails.

Source

pub async fn load_all_skill_trust( &self, ) -> Result<Vec<SkillTrustRow>, MemoryError>

Load all skill trust entries.

§Errors

Returns an error if the query fails.

Source

pub async fn set_skill_trust_level( &self, skill_name: &str, trust_level: &str, ) -> Result<bool, MemoryError>

Update only the trust level for a skill.

§Errors

Returns an error if the skill does not exist or the update fails.

Source

pub async fn delete_skill_trust( &self, skill_name: &str, ) -> Result<bool, MemoryError>

Delete trust entry for a skill.

§Errors

Returns an error if the delete fails.

Source

pub async fn update_skill_hash( &self, skill_name: &str, blake3_hash: &str, ) -> Result<bool, MemoryError>

Update the blake3 hash for a skill.

§Errors

Returns an error if the update fails.

Source§

impl SqliteStore

Source

pub async fn new(path: &str) -> Result<Self, MemoryError>

Open (or create) the SQLite database and run migrations.

Enables foreign key constraints at connection level so that ON DELETE CASCADE and other FK rules are enforced.

§Errors

Returns an error if the database cannot be opened or migrations fail.

Source

pub fn pool(&self) -> &SqlitePool

Expose the underlying pool for shared access by other stores.

Source

pub async fn run_migrations(pool: &SqlitePool) -> Result<(), MemoryError>

Run all migrations on the given pool.

§Errors

Returns an error if any migration fails.

Trait Implementations§

Source§

impl Clone for SqliteStore

Source§

fn clone(&self) -> SqliteStore

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

impl Debug for SqliteStore

Source§

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

Formats the value using the given formatter. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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