Skip to main content

ModelOps

Trait ModelOps 

Source
pub trait ModelOps: Model {
    // Required methods
    fn save(
        &mut self,
        db: &Db,
    ) -> impl Future<Output = Result<(), OrmError>> + Send;
    fn delete(
        &self,
        db: &Db,
    ) -> impl Future<Output = Result<u64, OrmError>> + Send;
    fn refresh(
        &mut self,
        db: &Db,
    ) -> impl Future<Output = Result<(), OrmError>> + Send;
}
Expand description

Persistence operations available on every Model.

Required Methods§

Source

fn save(&mut self, db: &Db) -> impl Future<Output = Result<(), OrmError>> + Send

Insert or update this object.

An is_unsaved object is inserted (generated columns omitted) and receives its key. Otherwise the row is updated by primary key, falling back to an insert when no row exists.

§Errors

Capability or backend errors; BackendError::Constraint for unique / foreign-key violations; OrmError::Signal when a pre_save receiver aborts the save (nothing is written) or a post_save receiver fails (the row is already written).

Source

fn delete(&self, db: &Db) -> impl Future<Output = Result<u64, OrmError>> + Send

Delete this object’s row, returning the number of rows removed (0 if it no longer exists). Dependent rows follow the database’s foreign-key actions.

§Errors

Capability or backend errors (e.g. a RESTRICT foreign key); OrmError::Signal from pre_delete (aborts) or post_delete (after the row is gone). post_delete is skipped when no row matched.

Source

fn refresh( &mut self, db: &Db, ) -> impl Future<Output = Result<(), OrmError>> + Send

Reload every column from the database, replacing *self.

§Errors

QueryError::DoesNotExist if the row is gone.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M: Model> ModelOps for M