umi_memory/storage/
backend.rs

1//! Storage Backend Trait
2//!
3//! TigerStyle: Abstract interface for entity storage.
4//!
5//! # Simulation-First
6//!
7//! Tests are written using SimStorageBackend before PostgresBackend.
8//! All implementations must satisfy the same trait contract.
9
10use async_trait::async_trait;
11
12use super::entity::{Entity, EntityType};
13use super::error::StorageResult;
14
15/// Abstract storage backend for entities.
16///
17/// TigerStyle: All operations are async, return explicit errors.
18#[async_trait]
19pub trait StorageBackend: Send + Sync {
20    /// Store or update an entity.
21    ///
22    /// If entity with same ID exists, it is updated.
23    /// Returns the entity ID.
24    async fn store_entity(&self, entity: &Entity) -> StorageResult<String>;
25
26    /// Get an entity by ID.
27    ///
28    /// Returns None if entity does not exist.
29    async fn get_entity(&self, id: &str) -> StorageResult<Option<Entity>>;
30
31    /// Delete an entity by ID.
32    ///
33    /// Returns true if entity existed and was deleted.
34    async fn delete_entity(&self, id: &str) -> StorageResult<bool>;
35
36    /// Search entities by text query.
37    ///
38    /// Simple text matching for SimStorageBackend.
39    /// Vector/semantic search for PostgresBackend.
40    async fn search(&self, query: &str, limit: usize) -> StorageResult<Vec<Entity>>;
41
42    /// List entities with optional type filter.
43    async fn list_entities(
44        &self,
45        entity_type: Option<EntityType>,
46        limit: usize,
47        offset: usize,
48    ) -> StorageResult<Vec<Entity>>;
49
50    /// Count entities with optional type filter.
51    async fn count_entities(&self, entity_type: Option<EntityType>) -> StorageResult<usize>;
52
53    /// Clear all entities.
54    ///
55    /// Primarily for testing.
56    async fn clear(&self) -> StorageResult<()>;
57}