Storage

Struct Storage 

Source
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: TargetRepository

Implementations§

Source§

impl Storage

Source

pub fn new(paths: EnvelopePaths) -> Result<Self, EnvelopeError>

Create a new Storage instance

Source

pub fn paths(&self) -> &EnvelopePaths

Get the paths configuration

Source

pub fn audit(&self) -> &AuditLogger

Get a reference to the audit logger

Source

pub fn log_audit(&self, entry: &AuditEntry) -> EnvelopeResult<()>

Log an audit entry

Source

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

Source

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

Source

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

Source

pub fn read_audit_log(&self, count: usize) -> EnvelopeResult<Vec<AuditEntry>>

Read recent audit entries

Source

pub fn load_all(&mut self) -> Result<(), EnvelopeError>

Load all data from disk

Source

pub fn save_all(&self) -> Result<(), EnvelopeError>

Save all data to disk

Source

pub fn is_initialized(&self) -> bool

Check if storage has been initialized (has any data)

Source

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.

Source

pub fn create_backup_with_retention( &self, retention: BackupRetention, ) -> EnvelopeResult<(PathBuf, Vec<PathBuf>)>

Create a backup with a custom retention policy

Source

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.

Source

pub fn backup_manager(&self, retention: BackupRetention) -> BackupManager

Get the backup manager for advanced backup operations

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.