rustorm-core 0.1.1

Core traits, types and utilities for RustORM
Documentation
use crate::error::OrmResult;
use async_trait::async_trait;
use sqlx::PgPool;

/// Хуки жизненного цикла модели.
///
/// Реализуйте только те методы, которые нужны.
/// Все методы по умолчанию — no-op (возвращают `Ok(())`).
#[async_trait]
pub trait Hooks: Sized + Send + Sync + 'static {
    /// Перед любым сохранением (INSERT или UPDATE).
    async fn before_save(&mut self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// После любого сохранения.
    async fn after_save(&self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// Перед INSERT.
    async fn before_create(&mut self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// После INSERT.
    async fn after_create(&self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// Перед UPDATE.
    async fn before_update(&mut self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// После UPDATE.
    async fn after_update(&self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// Перед DELETE.
    async fn before_delete(&self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
    /// После DELETE.
    async fn after_delete(&self, _pool: &PgPool) -> OrmResult<()> {
        Ok(())
    }
}