sea-orm-soft-delete 0.1.2

Soft deletes for SeaORM: trash, restore, prune, and queries that skip trashed rows
Documentation
use sea_orm::DbErr;

/// Turns `SeaORM`'s plain model `delete` into an error, so a row of a soft-deletable
/// entity leaves through [`soft_delete`](crate::SoftDeleteModel::soft_delete) or,
/// deliberately, [`force_delete`](crate::SoftDeleteModel::force_delete).
///
/// `SeaORM`'s `delete()` always removes the row, even on a soft-deleting entity,
/// so one call in the wrong place would erase data. Call this from the entity's
/// `before_delete` hook.
///
/// The hook runs only for `ActiveModel::delete` and `Model::delete`. Bulk deletes
/// (`Entity::delete_many()`, `Entity::delete_by_id(...)`) skip hooks in `SeaORM`, so
/// the guard cannot stop them; keep those out of code paths for this entity.
///
///
/// ```
/// # mod posts {
/// #     use sea_orm::entity::prelude::*;
/// #     #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
/// #     #[sea_orm(table_name = "posts")]
/// #     pub struct Model {
/// #         #[sea_orm(primary_key)]
/// #         pub id: i32,
/// #         pub category_id: i32,
/// #         pub slug: String,
/// #         pub deleted_at: Option<DateTimeWithTimeZone>,
/// #     }
/// #     #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
/// #     pub enum Relation {}
/// # }
/// # impl sea_orm_soft_delete::SoftDelete for posts::Entity {
/// #     fn deleted_at_column() -> Self::Column { posts::Column::DeletedAt }
/// # }
/// use sea_orm::{ActiveModelBehavior, ConnectionTrait, DbErr};
///
/// #[async_trait::async_trait]
/// impl ActiveModelBehavior for posts::ActiveModel {
///     async fn before_delete<C: ConnectionTrait>(self, _db: &C) -> Result<Self, DbErr> {
///         sea_orm_soft_delete::deny_hard_delete()?;
///         Ok(self)
///     }
/// }
/// # fn main() {}
/// ```
///
/// # Errors
///
/// Always: that is its job.
pub fn deny_hard_delete() -> Result<(), DbErr> {
    Err(DbErr::Custom(
        "hard delete is disabled for this entity: use soft_delete() or force_delete()".to_string(),
    ))
}