pub struct Storage {
pub accounts: AccountRepository,
pub transactions: TransactionRepository,
pub categories: CategoryRepository,
pub budget: BudgetRepository,
pub payees: PayeeRepository,
pub targets: TargetRepository,
/* private fields */
}Expand description
Main storage coordinator that provides access to all repositories and handles audit logging for all operations.
Fields§
§accounts: AccountRepository§transactions: TransactionRepository§categories: CategoryRepository§budget: BudgetRepository§payees: PayeeRepository§targets: TargetRepositoryImplementations§
Source§impl Storage
impl Storage
Sourcepub fn new(paths: EnvelopePaths) -> Result<Self, EnvelopeError>
pub fn new(paths: EnvelopePaths) -> Result<Self, EnvelopeError>
Create a new Storage instance
Sourcepub fn paths(&self) -> &EnvelopePaths
pub fn paths(&self) -> &EnvelopePaths
Get the paths configuration
Sourcepub fn audit(&self) -> &AuditLogger
pub fn audit(&self) -> &AuditLogger
Get a reference to the audit logger
Sourcepub fn log_audit(&self, entry: &AuditEntry) -> EnvelopeResult<()>
pub fn log_audit(&self, entry: &AuditEntry) -> EnvelopeResult<()>
Log an audit entry
Sourcepub fn log_create<T: Serialize>(
&self,
entity_type: EntityType,
entity_id: impl Into<String>,
entity_name: Option<String>,
entity: &T,
) -> EnvelopeResult<()>
pub fn log_create<T: Serialize>( &self, entity_type: EntityType, entity_id: impl Into<String>, entity_name: Option<String>, entity: &T, ) -> EnvelopeResult<()>
Log a create operation
Sourcepub fn log_update<T: Serialize>(
&self,
entity_type: EntityType,
entity_id: impl Into<String>,
entity_name: Option<String>,
before: &T,
after: &T,
diff_summary: Option<String>,
) -> EnvelopeResult<()>
pub fn log_update<T: Serialize>( &self, entity_type: EntityType, entity_id: impl Into<String>, entity_name: Option<String>, before: &T, after: &T, diff_summary: Option<String>, ) -> EnvelopeResult<()>
Log an update operation
Sourcepub fn log_delete<T: Serialize>(
&self,
entity_type: EntityType,
entity_id: impl Into<String>,
entity_name: Option<String>,
entity: &T,
) -> EnvelopeResult<()>
pub fn log_delete<T: Serialize>( &self, entity_type: EntityType, entity_id: impl Into<String>, entity_name: Option<String>, entity: &T, ) -> EnvelopeResult<()>
Log a delete operation
Sourcepub fn read_audit_log(&self, count: usize) -> EnvelopeResult<Vec<AuditEntry>>
pub fn read_audit_log(&self, count: usize) -> EnvelopeResult<Vec<AuditEntry>>
Read recent audit entries
Sourcepub fn load_all(&mut self) -> Result<(), EnvelopeError>
pub fn load_all(&mut self) -> Result<(), EnvelopeError>
Load all data from disk
Sourcepub fn save_all(&self) -> Result<(), EnvelopeError>
pub fn save_all(&self) -> Result<(), EnvelopeError>
Save all data to disk
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if storage has been initialized (has any data)
Sourcepub fn create_backup(&self) -> EnvelopeResult<PathBuf>
pub fn create_backup(&self) -> EnvelopeResult<PathBuf>
Create a backup of all data
Creates a backup using the default retention policy. Returns the path to the created backup file.
Sourcepub fn create_backup_with_retention(
&self,
retention: BackupRetention,
) -> EnvelopeResult<(PathBuf, Vec<PathBuf>)>
pub fn create_backup_with_retention( &self, retention: BackupRetention, ) -> EnvelopeResult<(PathBuf, Vec<PathBuf>)>
Create a backup with a custom retention policy
Sourcepub fn restore_from_backup(
&mut self,
backup_path: &Path,
) -> EnvelopeResult<RestoreResult>
pub fn restore_from_backup( &mut self, backup_path: &Path, ) -> EnvelopeResult<RestoreResult>
Restore data from a backup file
WARNING: This will overwrite all current data. It’s recommended to create a backup before restoring.
Sourcepub fn backup_manager(&self, retention: BackupRetention) -> BackupManager
pub fn backup_manager(&self, retention: BackupRetention) -> BackupManager
Get the backup manager for advanced backup operations
Sourcepub fn backup_before_destructive(&self) -> EnvelopeResult<Option<PathBuf>>
pub fn backup_before_destructive(&self) -> EnvelopeResult<Option<PathBuf>>
Create a backup before a destructive operation if needed
This creates a backup only if:
- No backup exists yet, OR
- The most recent backup is older than 60 seconds
This prevents creating too many backups when multiple destructive operations happen in quick succession.
Returns Ok(Some(path)) if a backup was created, Ok(None) if skipped.
Auto Trait Implementations§
impl !Freeze for Storage
impl RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnwindSafe for Storage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more