pub struct ActiveModel<M: Model> {
pub inner: M,
/* private fields */
}Expand description
A smart wrapper around a Model tracking modified columns dynamically.
Used to perform targeted, minimal UPDATE or INSERT queries that only
persist the columns that have actually changed.
Fields§
§inner: MThe underlying model instance.
Implementations§
Source§impl<M: Model> ActiveModel<M>
impl<M: Model> ActiveModel<M>
Sourcepub fn new_insert(model: M) -> Self
pub fn new_insert(model: M) -> Self
Create a new ActiveModel for an entity that hasn’t been saved yet.
Sourcepub fn from_model(model: M) -> Self
pub fn from_model(model: M) -> Self
Wrap an existing model into an ActiveModel state tracker for updates.
Sourcepub fn set<T: ToSql>(&mut self, column: &'static str, value: T)
pub fn set<T: ToSql>(&mut self, column: &'static str, value: T)
Flag a column as modified and stage its value for an upcoming transaction.
Sourcepub fn has_changes(&self) -> bool
pub fn has_changes(&self) -> bool
Returns whether any columns have been modified.
Sourcepub fn changed_columns(&self) -> Vec<&'static str>
pub fn changed_columns(&self) -> Vec<&'static str>
Returns the list of changed column names.
Sourcepub fn is_new(&self) -> bool
pub fn is_new(&self) -> bool
Evaluates whether the underlying model has not been persisted yet.
Sourcepub fn save(&mut self, executor: &mut impl Executor) -> OrmResult<()>
pub fn save(&mut self, executor: &mut impl Executor) -> OrmResult<()>
Intelligently issues an INSERT or UPDATE depending on is_new() state.
Validates the model before persisting.
Trait Implementations§
Auto Trait Implementations§
impl<M> Freeze for ActiveModel<M>where
M: Freeze,
impl<M> RefUnwindSafe for ActiveModel<M>where
M: RefUnwindSafe,
impl<M> Send for ActiveModel<M>
impl<M> Sync for ActiveModel<M>
impl<M> Unpin for ActiveModel<M>where
M: Unpin,
impl<M> UnsafeUnpin for ActiveModel<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for ActiveModel<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more