spark_orm/model/
observer.rs

1use crate::model::{Model, MongodbResult};
2
3/// This trait implement by default for Model
4/// but if user wants to override and use it must tell to Model macro
5/// ```rust
6/// #[Model(coll_name = "users", observer)]
7/// #[derive(Serialize, Deserialize, Debug, Default)]
8/// struct User {
9///    name: String,
10/// }
11/// ```
12
13#[allow(async_fn_in_trait)]
14#[allow(unused)]
15pub trait Observer<M> {
16    /// this call when document is created , in these observers can't call save again
17    #[inline]
18    async fn created(model: &mut Model<'_, M>) -> MongodbResult<()> {
19        Ok(())
20    }
21
22    /// this call when document is updated
23    /// it just called when user uses save method not update method
24    #[inline]
25    async fn updated(model: &mut Model<'_, M>) -> MongodbResult<()> {
26        Ok(())
27    }
28
29    /// this call when document is delete
30    #[inline]
31    async fn deleted(model: &mut Model<'_, M>) -> MongodbResult<()> {
32        Ok(())
33    }
34}