Expand description
OxiGDAL Offline - Offline-First Data Management
This crate provides comprehensive offline-first data management capabilities for OxiGDAL, including local storage, sync queue management, conflict resolution, and optimistic updates.
§Features
- Offline-first architecture: Local-first data layer with background sync
- Multi-platform storage: IndexedDB for WASM, SQLite for native platforms
- Sync queue management: Persistent queue with automatic retry
- Conflict detection: Automatic detection of concurrent modifications
- Merge strategies: Configurable strategies (Last-Write-Wins, Three-Way-Merge, Custom)
- Background sync: Automatic sync when connectivity is restored
- Optimistic updates: Immediate UI updates with eventual consistency
- Retry mechanisms: Exponential backoff with jitter
§Architecture
The offline system consists of several key components:
- Storage Layer: Abstraction over IndexedDB (WASM) and SQLite (native)
- Sync Queue: Persistent queue of pending operations
- Conflict Detector: Detects concurrent modifications
- Merge Engine: Resolves conflicts using configurable strategies
- Retry Manager: Handles failed sync attempts with exponential backoff
- Optimistic Update Tracker: Tracks optimistic changes for rollback
§Example
use oxigdal_offline::{OfflineManager, Config, MergeStrategy};
use oxigdal_offline::storage::StorageBackend;
// Configure offline manager
let config = Config::builder()
.max_queue_size(1000)
.merge_strategy(MergeStrategy::LastWriteWins)
.retry_max_attempts(5)
.build()?;
// Create offline manager
let manager = OfflineManager::new(config).await?;
// Write data (automatically queued for sync)
manager.write("key1", b"value1").await?;
// Read data (from local cache)
let value = manager.read("key1").await?;
// Sync when online
manager.sync().await?;§WASM Support
The crate is fully WASM-compatible, using IndexedDB for storage in browsers:
ⓘ
// Enable WASM feature in Cargo.toml
// oxigdal-offline = { version = "0.1", features = ["wasm"] }
use oxigdal_offline::OfflineManager;
use oxigdal_offline::error::Result;
async fn wasm_example() -> Result<()> {
let manager = OfflineManager::new_wasm("my-database").await?;
manager.write("key", b"value").await?;
Ok(())
}Re-exports§
pub use config::Config;pub use config::ConfigBuilder;pub use error::Error;pub use error::Result;pub use manager::OfflineManager;pub use merge::MergeStrategy;pub use types::Operation;pub use types::OperationId;pub use types::Record;pub use types::RecordId;pub use types::Version;
Modules§
- config
- Configuration for offline data management
- conflict
- Conflict detection for concurrent modifications
- error
- Error types for offline data management
- manager
- Main offline manager that coordinates all components
- merge
- Merge strategies for conflict resolution
- optimistic
- Optimistic update tracking for offline-first operations
- queue
- Sync queue management
- retry
- Retry mechanisms with exponential backoff
- storage
- Storage backends for offline data
- sync
- Synchronization engine for offline-first data
- types
- Core types for offline data management