pub struct SqlitePool { /* private fields */ }Expand description
Thread-safe SQLite connection wrapper.
Uses a Mutex<Connection> — sufficient for our single-process,
moderate-write workload. If we ever need concurrent writers,
switch to r2d2 or WAL mode (already enabled).
When an Encryptor is set, content columns are transparently
encrypted on write and decrypted on read by the store layers.
Implementations§
Source§impl SqlitePool
impl SqlitePool
Sourcepub fn schema_version(&self) -> Result<i64, SqliteError>
pub fn schema_version(&self) -> Result<i64, SqliteError>
Get the current schema version.
Source§impl SqlitePool
impl SqlitePool
Sourcepub fn open(path: &Path) -> Result<Self, SqliteError>
pub fn open(path: &Path) -> Result<Self, SqliteError>
Open a new SQLite database at the given path.
- Creates the file if it doesn’t exist
- Enables WAL mode for concurrent reads
- Enables foreign keys
- Runs all schema migrations
Sourcepub fn open_memory() -> Result<Self, SqliteError>
pub fn open_memory() -> Result<Self, SqliteError>
Open an in-memory database (for testing).
Sourcepub fn with_conn<F, T>(&self, f: F) -> Result<T, SqliteError>
pub fn with_conn<F, T>(&self, f: F) -> Result<T, SqliteError>
Execute a closure with an exclusive lock on the connection.
Sourcepub fn with_encryptor(self, enc: Encryptor) -> Self
pub fn with_encryptor(self, enc: Encryptor) -> Self
Attach an encryptor to this pool (builder pattern).
Once set, encrypt_content / decrypt_content are active on all
store layers that use this pool.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Returns true if an encryptor is active.
Sourcepub fn encrypt_content(&self, plaintext: &str) -> String
pub fn encrypt_content(&self, plaintext: &str) -> String
Encrypt a string if encryption is enabled, otherwise return as-is.
Sourcepub fn decrypt_content(&self, maybe_ciphertext: &str) -> String
pub fn decrypt_content(&self, maybe_ciphertext: &str) -> String
Decrypt a string if encryption is enabled.
Falls back to returning the input unchanged if decryption fails (e.g. legacy plaintext rows written before encryption was enabled).
Sourcepub fn try_decrypt_content(&self, maybe_ciphertext: &str) -> Option<String>
pub fn try_decrypt_content(&self, maybe_ciphertext: &str) -> Option<String>
Try to decrypt a string, returning None if decryption fails.
Unlike decrypt_content, this does NOT fall back to returning raw
ciphertext. Use this at read boundaries to filter out rows that
were encrypted with a different key or are corrupted.
Sourcepub fn wal_checkpoint(&self) -> Result<(), SqliteError>
pub fn wal_checkpoint(&self) -> Result<(), SqliteError>
Flush the WAL file into the main database file.
Should be called on graceful shutdown to ensure all committed writes are
fully persisted and the WAL file is clean. Uses TRUNCATE mode which
also resets the WAL to zero size.
Sourcepub fn insert_scheduled_intent(
&self,
description: &str,
cron: Option<&str>,
namespace: &str,
metadata: Option<&str>,
) -> Result<String, SqliteError>
pub fn insert_scheduled_intent( &self, description: &str, cron: Option<&str>, namespace: &str, metadata: Option<&str>, ) -> Result<String, SqliteError>
Persist a scheduled intent and return its generated ID.
Sourcepub fn list_scheduled_intents(
&self,
namespace: Option<&str>,
) -> Result<Vec<ScheduledIntent>, SqliteError>
pub fn list_scheduled_intents( &self, namespace: Option<&str>, ) -> Result<Vec<ScheduledIntent>, SqliteError>
List scheduled intents, optionally filtered by namespace.
Sourcepub fn update_scheduled_intent_status(
&self,
id: &str,
status: &str,
) -> Result<bool, SqliteError>
pub fn update_scheduled_intent_status( &self, id: &str, status: &str, ) -> Result<bool, SqliteError>
Update a scheduled intent status. Returns true when a row was updated.
Sourcepub fn cancel_scheduled_intent(&self, id: &str) -> Result<bool, SqliteError>
pub fn cancel_scheduled_intent(&self, id: &str) -> Result<bool, SqliteError>
Cancel a scheduled intent (set status to “cancelled”).
Sourcepub fn due_scheduled_intents(&self) -> Result<Vec<ScheduledIntent>, SqliteError>
pub fn due_scheduled_intents(&self) -> Result<Vec<ScheduledIntent>, SqliteError>
Return all scheduled intents with status "scheduled" (i.e. pending execution).
Sourcepub fn insert_notification(
&self,
content: &str,
priority: i32,
triggered_by: &str,
channel: Option<&str>,
) -> Result<String, SqliteError>
pub fn insert_notification( &self, content: &str, priority: i32, triggered_by: &str, channel: Option<&str>, ) -> Result<String, SqliteError>
Insert a notification into the outbox for later delivery.
Sourcepub fn pending_notifications(
&self,
limit: usize,
) -> Result<Vec<Notification>, SqliteError>
pub fn pending_notifications( &self, limit: usize, ) -> Result<Vec<Notification>, SqliteError>
Fetch all pending (undelivered) notifications, ordered by priority then age.
Sourcepub fn mark_notification_delivered(&self, id: &str) -> Result<bool, SqliteError>
pub fn mark_notification_delivered(&self, id: &str) -> Result<bool, SqliteError>
Mark a notification as delivered (sets delivered_at to now).
Sourcepub fn mark_notifications_delivered(
&self,
ids: &[String],
) -> Result<usize, SqliteError>
pub fn mark_notifications_delivered( &self, ids: &[String], ) -> Result<usize, SqliteError>
Mark multiple notifications as delivered in a single UPDATE. Returns the count of notifications actually marked delivered.
Sourcepub fn prune_notifications(
&self,
max_age_days: u32,
) -> Result<usize, SqliteError>
pub fn prune_notifications( &self, max_age_days: u32, ) -> Result<usize, SqliteError>
Prune old delivered notifications and stale undelivered ones.
Sourcepub fn export_all_facts(&self) -> Result<Vec<ExportedFact>, SqliteError>
pub fn export_all_facts(&self) -> Result<Vec<ExportedFact>, SqliteError>
Export all semantic facts ordered by ID.
Sourcepub fn export_all_episodes(&self) -> Result<Vec<ExportedEpisode>, SqliteError>
pub fn export_all_episodes(&self) -> Result<Vec<ExportedEpisode>, SqliteError>
Export all episodes with session info, ordered by timestamp.
Sourcepub fn import_facts(
&self,
facts: &[ExportedFact],
) -> Result<(usize, Vec<usize>), SqliteError>
pub fn import_facts( &self, facts: &[ExportedFact], ) -> Result<(usize, Vec<usize>), SqliteError>
Import facts (ON CONFLICT DO NOTHING). Returns (imported_count, new_indices).
Sourcepub fn import_episodes(
&self,
episodes: &[ExportedEpisode],
) -> Result<usize, SqliteError>
pub fn import_episodes( &self, episodes: &[ExportedEpisode], ) -> Result<usize, SqliteError>
Import episodes (ON CONFLICT DO NOTHING). Returns count of newly imported episodes.
Sourcepub fn table_stats(&self) -> Result<Vec<(String, i64)>, SqliteError>
pub fn table_stats(&self) -> Result<Vec<(String, i64)>, SqliteError>
Get table row counts for status display.
Trait Implementations§
Source§impl Clone for SqlitePool
impl Clone for SqlitePool
Source§fn clone(&self) -> SqlitePool
fn clone(&self) -> SqlitePool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SqlitePool
impl RefUnwindSafe for SqlitePool
impl Send for SqlitePool
impl Sync for SqlitePool
impl Unpin for SqlitePool
impl UnsafeUnpin for SqlitePool
impl UnwindSafe for SqlitePool
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
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>
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>
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