Skip to main content

Module in_memory

Module in_memory 

Source
Expand description

In-Memory Store - Generic Testing and Prototyping Utility

Provides a thread-safe, async-compatible in-memory storage implementation for use in testing, prototyping, and development environments.

§Features

  • Generic storage for any Clone + Send + Sync type
  • Soft delete with trash/restore functionality
  • Pagination support
  • Thread-safe using RwLock
  • Async-compatible

§Example

ⓘ
use backbone_orm::InMemoryStore;

#[derive(Clone)]
struct User {
    id: String,
    name: String,
}

#[tokio::main]
async fn main() {
    let store = InMemoryStore::<User>::new();

    // Insert
    let user = User { id: "1".to_string(), name: "Alice".to_string() };
    store.insert("1".to_string(), user.clone()).await;

    // Get
    let found = store.get("1").await;
    assert!(found.is_some());

    // Soft delete
    store.soft_delete("1").await;
    assert!(store.get("1").await.is_none());

    // Restore
    store.restore("1").await;
    assert!(store.get("1").await.is_some());
}

Structs§

InMemoryStore
Generic in-memory store for entities