Module dir_storage

Module dir_storage 

Source
Expand description

Directory-based storage layer for managing multiple entity files.

Provides per-entity file storage with ACID guarantees, automatic migrations, and flexible file naming strategies. Unlike FileStorage which stores multiple entities in a single file, DirStorage creates one file per entity.

§Use Cases

  • Session management: sessions/session-123.json
  • Task management: tasks/task-456.json
  • User data: users/user-789.json

§Example

use version_migrate::{AppPaths, Migrator, DirStorage, DirStorageStrategy};

// Setup migrator with entity paths
let mut migrator = Migrator::new();
let session_path = Migrator::define("session")
    .from::<SessionV1_0_0>()
    .step::<SessionV1_1_0>()
    .into_with_save::<SessionEntity>();
migrator.register(session_path)?;

// Create DirStorage
let paths = AppPaths::new("myapp");
let storage = DirStorage::new(
    paths,
    "sessions",
    migrator,
    DirStorageStrategy::default(),
)?;

// Save and load entities
let session = SessionEntity { /* ... */ };
storage.save("session", "session-123", session)?;
let loaded: SessionEntity = storage.load("session", "session-123")?;

Re-exports§

pub use crate::storage::AtomicWriteConfig;
pub use crate::storage::FormatStrategy;

Structs§

DirStorage
Directory-based entity storage with ACID guarantees and automatic migrations.
DirStorageStrategy
Strategy configuration for directory-based storage operations.

Enums§

FilenameEncoding
File naming encoding strategy for entity IDs.