Trait musty::Model

source ·
pub trait Model<I>where
    Self: Sized + Send + Sync + Serialize + DeserializeOwned + Unpin,
    I: IdGuard,
{ fn id(&self) -> &Id<Self, I>; fn set_id(&mut self, id: Id<Self, I>); fn get_by_id<'life0, 'async_trait, B, T>(
        db: &'life0 Db<B>,
        id: T
    ) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
    where
        Self: Context<I, B> + 'static + Send + 'async_trait,
        T: Into<Id<Self, I>> + Send + Sync + 'async_trait,
        B: Backend + 'async_trait,
        'life0: 'async_trait
, { ... } fn save<'life0, 'life1, 'async_trait, B>(
        &'life0 mut self,
        db: &'life1 Db<B>
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
    where
        Self: Context<I, B> + 'static + Send + 'async_trait,
        B: Backend + 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
, { ... } fn delete<'life0, 'life1, 'async_trait, B>(
        &'life0 mut self,
        db: &'life1 Db<B>
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
    where
        Self: Context<I, B> + 'static + Send + 'async_trait,
        B: Backend + 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
, { ... } fn find_one<'life0, 'async_trait, B>(
        db: &'life0 Db<B>,
        filter: B::Filter
    ) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
    where
        Self: Context<I, B> + 'static + Send + 'async_trait,
        B: Backend + 'async_trait,
        'life0: 'async_trait
, { ... } }
Expand description

Exposes basic database operations for a model.

This trait is database-agnostic and only exposes basic database operations. More complex database-specific operations are implemented in other traits, such as MongoModel.

Most of the time you should not need to implement this trait yourself. Instead, use the model macro. Ideally, you should try to use only the generic operations provided by this trait, and avoid using database-specific operations unless absolutely necessary.

The #[model] macro

The #[model] macro makes it very straight-forward to derive Model for your structs.

Required Methods§

Get the ID of this model.

Set the ID of this model.

Provided Methods§

Get a model by its ID from a database.

Save this model to a database.

Delete this model from a database.

Find a single model from a database by a filter.

Implementors§