pub struct SqlitePool { /* private fields */ }Expand description
Thread-safe SQLite connection wrapper.
Backed by an r2d2 pool of rusqlite::Connections with WAL mode
enabled, so concurrent reads can proceed in parallel (writes are
still serialized at the SQLite level). Replaces the previous
Arc<Mutex<Connection>> shape that funnelled every operation
through a single mutex (Wave F, Issue 68).
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 latest_schema_version() -> i64
pub fn latest_schema_version() -> i64
The highest schema version this build knows how to apply — the
version a freshly migrated database lands on. Used by the open-time
reconciliation gate to detect a future (downgrade) schema and by
doctor to report binary-vs-disk skew.
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
- Reconciles the on-disk schema version against this build (refuses a future schema; snapshots before a forward migration)
- Runs all schema migrations
Sourcepub fn open_with(
path: &Path,
allow_downgrade: bool,
) -> Result<Self, SqliteError>
pub fn open_with( path: &Path, allow_downgrade: bool, ) -> Result<Self, SqliteError>
Like SqlitePool::open, but allow_downgrade suppresses the
SqliteError::SchemaTooNew guard so an older binary can be forced
onto a newer on-disk schema. The forward-only migration runner still
won’t alter the schema downward — this only un-gates the open so a
recovery/export path can read what it can.
Sourcepub fn open_memory() -> Result<Self, SqliteError>
pub fn open_memory() -> Result<Self, SqliteError>
Open an in-memory database (for testing).
Pool size is forced to 1 — multiple Connection::open_in_memory
handles each get a fresh DB, which would break any test that
writes from one checkout and reads from another. Single
connection preserves the legacy single-connection semantics.
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 a connection borrowed from the pool.
The connection returns to the pool when the closure exits. Multiple concurrent readers can hold distinct connections at the same time; writes still serialize at the SQLite level (single-writer is fundamental to SQLite, WAL or not).
Sourcepub fn open_connections(&self) -> u32
pub fn open_connections(&self) -> u32
Number of connections the r2d2 pool currently holds (idle + checked
out), capped by the configured max_size. Backs the open-connections
resource gauge; a value pinned at the max for a sustained period is a
sign of connection-pressure or a leak.
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 !RefUnwindSafe for SqlitePool
impl !UnwindSafe for SqlitePool
impl Freeze for SqlitePool
impl Send for SqlitePool
impl Sync for SqlitePool
impl Unpin for SqlitePool
impl UnsafeUnpin 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