sea_orm_soft_delete/lib.rs
1//! Soft deletes for [SeaORM](https://www.sea-ql.org/SeaORM/): a row is moved to the
2//! trash by setting `deleted_at`, can be restored, and is pruned for good later.
3//!
4//! ```
5//! # mod posts {
6//! # use sea_orm::entity::prelude::*;
7//! # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
8//! # #[sea_orm(table_name = "posts")]
9//! # pub struct Model {
10//! # #[sea_orm(primary_key)]
11//! # pub id: i32,
12//! # pub category_id: i32,
13//! # pub slug: String,
14//! # pub deleted_at: Option<DateTimeWithTimeZone>,
15//! # }
16//! # #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
17//! # pub enum Relation {}
18//! # }
19//! # impl sea_orm::ActiveModelBehavior for posts::ActiveModel {}
20//! use sea_orm::{DatabaseConnection, DbErr, EntityTrait};
21//! use sea_orm_soft_delete::{SoftDelete, SoftDeleteModel};
22//!
23//! impl SoftDelete for posts::Entity {
24//! fn deleted_at_column() -> Self::Column {
25//! posts::Column::DeletedAt
26//! }
27//! }
28//!
29//! async fn example(db: &DatabaseConnection, post: posts::Model) -> Result<(), DbErr> {
30//! let post = post.soft_delete(db).await?; // deleted_at = now
31//! let live = posts::Entity::find_without_trashed().all(db).await?;
32//! let post = post.restore(db).await?; // deleted_at = NULL
33//! Ok(())
34//! }
35//! # fn main() {}
36//! ```
37//!
38//! `SeaORM` has no global query scopes, so `Entity::find()` still returns trashed
39//! rows. Use [`SoftDelete::find_without_trashed`] or
40//! [`TrashedQuery::without_trashed`] wherever trashed rows must stay hidden.
41
42mod entity;
43mod guard;
44mod model;
45mod query;
46mod row;
47mod schema;
48
49pub use entity::SoftDelete;
50pub use guard::deny_hard_delete;
51pub use model::SoftDeleteModel;
52pub use query::TrashedQuery;
53pub use schema::{deleted_at_column, unique_while_kept};