pub struct SqliteStore { /* private fields */ }Expand description
SQLite-backed storage for the Bitcoin Knowledge Base.
Uses rusqlite with bundled FTS5 for full-text search.
All database access is serialized through a Mutex<Connection>.
Implementations§
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open (or create) a database at the given path and run migrations.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Create an in-memory database (for tests).
Sourcepub async fn upsert_document(&self, doc: &Document) -> Result<()>
pub async fn upsert_document(&self, doc: &Document) -> Result<()>
Insert or update a document, appending to the change log.
Sourcepub async fn insert_reference(&self, reference: &Reference) -> Result<()>
pub async fn insert_reference(&self, reference: &Reference) -> Result<()>
Insert a cross-reference.
Sourcepub async fn delete_refs_from(&self, doc_id: &str) -> Result<()>
pub async fn delete_refs_from(&self, doc_id: &str) -> Result<()>
Delete all references originating from a document (for re-enrichment).
Sourcepub async fn upsert_concept_mention(
&self,
doc_id: &str,
concept_slug: &str,
confidence: f32,
) -> Result<()>
pub async fn upsert_concept_mention( &self, doc_id: &str, concept_slug: &str, confidence: f32, ) -> Result<()>
Insert or replace a concept mention for a document.
Sourcepub async fn delete_concept_mentions(&self, doc_id: &str) -> Result<()>
pub async fn delete_concept_mentions(&self, doc_id: &str) -> Result<()>
Delete all concept mentions for a document (for re-enrichment).
Sourcepub async fn reset_source_type(
&self,
source_type: &str,
sync_id_patterns: &[String],
) -> Result<u64>
pub async fn reset_source_type( &self, source_type: &str, sync_id_patterns: &[String], ) -> Result<u64>
Delete all documents, refs, concept mentions, and sync state for a given source type. Returns the number of documents deleted.
Sourcepub async fn docs_for_reenrich(
&self,
source_type: &str,
) -> Result<Vec<(String, Option<String>, Option<String>)>>
pub async fn docs_for_reenrich( &self, source_type: &str, ) -> Result<Vec<(String, Option<String>, Option<String>)>>
Return all document IDs and bodies for a given source type, for re-enrichment. Streams in batches to avoid loading everything into memory at once.
Sourcepub async fn get_stats(&self) -> Result<Vec<(String, i64)>>
pub async fn get_stats(&self) -> Result<Vec<(String, i64)>>
Get document counts grouped by source type.
Sourcepub async fn get_all_sync_states(&self) -> Result<Vec<SyncState>>
pub async fn get_all_sync_states(&self) -> Result<Vec<SyncState>>
Get all sync states.
Sourcepub async fn compact_change_log(&self, max_age: Duration) -> Result<u64>
pub async fn compact_change_log(&self, max_age: Duration) -> Result<u64>
Compact the change log by deleting entries older than the given duration.
Sourcepub async fn get_sync_state(&self, source_id: &str) -> Result<Option<SyncState>>
pub async fn get_sync_state(&self, source_id: &str) -> Result<Option<SyncState>>
Get or create sync state for a source.
Sourcepub async fn update_sync_state(&self, state: &SyncState) -> Result<()>
pub async fn update_sync_state(&self, state: &SyncState) -> Result<()>
Update sync state after a sync cycle.