pub enum ActiveValue<V>{
Set(V),
Unchanged(V),
NotSet,
}
Expand description
Defines a stateful value used in ActiveModel.
There are three possible state represented by three enum variants.
- ActiveValue::Set: A defined Value actively being set
- ActiveValue::Unchanged: A defined Value remain unchanged
- ActiveValue::NotSet: An undefined Value
The stateful value is useful when constructing UPDATE SQL statement, see an example below.
§Examples
use sea_orm::tests_cfg::{cake, fruit};
use sea_orm::{entity::*, query::*, DbBackend};
// The code snipped below does an UPDATE operation on a `ActiveValue`
assert_eq!(
Update::one(fruit::ActiveModel {
id: ActiveValue::set(1),
name: ActiveValue::set("Orange".to_owned()),
cake_id: ActiveValue::not_set(),
})
.build(DbBackend::Postgres)
.to_string(),
r#"UPDATE "fruit" SET "name" = 'Orange' WHERE "fruit"."id" = 1"#
);
Variants§
Set(V)
A defined Value actively being set
Unchanged(V)
A defined Value remain unchanged
NotSet
An undefined Value
Implementations§
Source§impl<V> ActiveValue<V>
impl<V> ActiveValue<V>
Sourcepub fn set(value: V) -> ActiveValue<V>
pub fn set(value: V) -> ActiveValue<V>
Create an ActiveValue::Set
Sourcepub fn is_set(&self) -> bool
pub fn is_set(&self) -> bool
Check if the ActiveValue is ActiveValue::Set
Sourcepub fn unchanged(value: V) -> ActiveValue<V>
pub fn unchanged(value: V) -> ActiveValue<V>
Create an ActiveValue::Unchanged
Sourcepub fn is_unchanged(&self) -> bool
pub fn is_unchanged(&self) -> bool
Check if the ActiveValue is ActiveValue::Unchanged
Sourcepub fn not_set() -> ActiveValue<V>
pub fn not_set() -> ActiveValue<V>
Create an ActiveValue::NotSet
Sourcepub fn is_not_set(&self) -> bool
pub fn is_not_set(&self) -> bool
Check if the ActiveValue is ActiveValue::NotSet
Sourcepub fn take(&mut self) -> Option<V>
pub fn take(&mut self) -> Option<V>
Get the mutable value an ActiveValue also setting itself to ActiveValue::NotSet
Sourcepub fn into_value(self) -> Option<Value>
pub fn into_value(self) -> Option<Value>
Check if a Value exists or not
Sourcepub fn into_wrapped_value(self) -> ActiveValue<Value>
pub fn into_wrapped_value(self) -> ActiveValue<Value>
Wrap the Value into a ActiveValue<Value>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the value from ActiveValue::Unchanged to ActiveValue::Set, leaving ActiveValue::NotSet untouched.
Trait Implementations§
Source§impl<V> AsRef<V> for ActiveValue<V>
impl<V> AsRef<V> for ActiveValue<V>
Source§impl<V> Clone for ActiveValue<V>
impl<V> Clone for ActiveValue<V>
Source§fn clone(&self) -> ActiveValue<V>
fn clone(&self) -> ActiveValue<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<V> Debug for ActiveValue<V>
impl<V> Debug for ActiveValue<V>
Source§impl<V> Default for ActiveValue<V>
impl<V> Default for ActiveValue<V>
Source§fn default() -> ActiveValue<V>
fn default() -> ActiveValue<V>
Create an ActiveValue::NotSet
Source§impl<V> From<ActiveValue<V>> for ActiveValue<Option<V>>
impl<V> From<ActiveValue<V>> for ActiveValue<Option<V>>
Source§fn from(value: ActiveValue<V>) -> ActiveValue<Option<V>>
fn from(value: ActiveValue<V>) -> ActiveValue<Option<V>>
Source§impl<V> PartialEq for ActiveValue<V>
impl<V> PartialEq for ActiveValue<V>
Auto Trait Implementations§
impl<V> Freeze for ActiveValue<V>where
V: Freeze,
impl<V> RefUnwindSafe for ActiveValue<V>where
V: RefUnwindSafe,
impl<V> Send for ActiveValue<V>where
V: Send,
impl<V> Sync for ActiveValue<V>where
V: Sync,
impl<V> Unpin for ActiveValue<V>where
V: Unpin,
impl<V> UnwindSafe for ActiveValue<V>where
V: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more