Enum leetcode_tui_rs::migrations::sea_orm::ActiveValue
source · pub enum ActiveValue<V>where
V: Into<Value>,{
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>where
V: Into<Value>,
impl<V> ActiveValue<V>where V: Into<Value>,
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 is 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> Clone for ActiveValue<V>where
V: Clone + Into<Value>,
impl<V> Clone for ActiveValue<V>where V: Clone + Into<Value>,
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> Default for ActiveValue<V>where
V: Into<Value>,
impl<V> Default for ActiveValue<V>where V: Into<Value>,
source§fn default() -> ActiveValue<V>
fn default() -> ActiveValue<V>
Create an ActiveValue::NotSet
source§impl<V> From<ActiveValue<V>> for ActiveValue<Option<V>>where
V: Into<Value> + Nullable,
impl<V> From<ActiveValue<V>> for ActiveValue<Option<V>>where V: Into<Value> + Nullable,
source§fn from(value: ActiveValue<V>) -> ActiveValue<Option<V>>
fn from(value: ActiveValue<V>) -> ActiveValue<Option<V>>
source§impl<V> PartialEq<ActiveValue<V>> for ActiveValue<V>where
V: Into<Value> + PartialEq<V>,
impl<V> PartialEq<ActiveValue<V>> for ActiveValue<V>where V: Into<Value> + PartialEq<V>,
source§fn eq(&self, other: &ActiveValue<V>) -> bool
fn eq(&self, other: &ActiveValue<V>) -> bool
self
and other
values to be equal, and is used
by ==
.