Skip to main content

FlozHooks

Trait FlozHooks 

Source
pub trait FlozHooks: Sized {
    // Provided methods
    fn before_create(&self) -> Result<(), FlozError> { ... }
    fn after_create(&self) { ... }
    fn before_save(&mut self) -> Result<(), FlozError> { ... }
    fn after_save(&self) { ... }
    fn before_delete(&self) -> Result<(), FlozError> { ... }
    fn after_delete(&self) { ... }
}
Expand description

Lifecycle hooks for database operations.

before_* hooks return Result — returning Err(...) aborts the operation. after_* hooks are fire-and-forget notifications.

Provided Methods§

Source

fn before_create(&self) -> Result<(), FlozError>

Called before create(). Return Err to abort the INSERT.

Takes &self (immutable). Modify fields before calling create().

Source

fn after_create(&self)

Called after a successful create().

Source

fn before_save(&mut self) -> Result<(), FlozError>

Called before save(). Can modify the entity (e.g., set updated_at). Return Err to abort the UPDATE.

If this hook sets a field via set_*(), the field becomes dirty and will be included in the UPDATE statement.

Source

fn after_save(&self)

Called after a successful save().

Source

fn before_delete(&self) -> Result<(), FlozError>

Called before delete(). Return Err to abort the DELETE.

Source

fn after_delete(&self)

Called after a successful delete().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§