sea_orm/entity/active_value.rs
1use crate::Value;
2use sea_query::Nullable;
3use std::fmt::Debug;
4
5pub use ActiveValue::{NotSet, Set, Unchanged};
6
7/// The state of a field in an [ActiveModel][crate::ActiveModelTrait].
8///
9/// There are three possible states represented by three enum variants:
10///
11/// - [Set] - a value that's explicitly set by the application and sent to the database.
12/// - [Unchanged] - an existing, unchanged value from the database.
13/// - [NotSet] - an undefined value (nothing is sent to the database).
14///
15/// The difference between these states is useful
16/// when constructing `INSERT` and `UPDATE` SQL statements (see an example below).
17/// It's also useful for knowing which fields have changed in a record.
18///
19/// # Examples
20///
21/// ```
22/// use sea_orm::tests_cfg::{cake, fruit};
23/// use sea_orm::{DbBackend, entity::*, query::*};
24///
25/// // Here, we use `NotSet` to let the database automatically generate an `id`.
26/// // This is different from `Set(None)` that explicitly sets `cake_id` to `NULL`.
27/// assert_eq!(
28/// Insert::one(fruit::ActiveModel {
29/// id: ActiveValue::NotSet,
30/// name: ActiveValue::Set("Orange".to_owned()),
31/// cake_id: ActiveValue::Set(None),
32/// })
33/// .build(DbBackend::Postgres)
34/// .to_string(),
35/// r#"INSERT INTO "fruit" ("name", "cake_id") VALUES ('Orange', NULL)"#
36/// );
37///
38/// // Here, we update the record, set `cake_id` to the new value
39/// // and use `NotSet` to avoid updating the `name` field.
40/// // `id` is the primary key, so it's used in the condition and not updated.
41/// assert_eq!(
42/// Update::one(fruit::ActiveModel {
43/// id: ActiveValue::Unchanged(1),
44/// name: ActiveValue::NotSet,
45/// cake_id: ActiveValue::Set(Some(2)),
46/// })
47/// .validate()
48/// .unwrap()
49/// .build(DbBackend::Postgres)
50/// .to_string(),
51/// r#"UPDATE "fruit" SET "cake_id" = 2 WHERE "fruit"."id" = 1"#
52/// );
53/// ```
54#[derive(Clone, Debug)]
55pub enum ActiveValue<V>
56where
57 V: Into<Value>,
58{
59 /// A [Value] that's explicitly set by the application and sent to the database.
60 ///
61 /// Use this to insert or set a specific value.
62 ///
63 /// When editing an existing value, you can use [set_ne][ActiveValue::set_ne]
64 /// to preserve the [Unchanged] state when the new value is the same as the old one.
65 /// Then you can meaningfully use methods like [crate::ActiveModelTrait::is_changed].
66 Set(V),
67 /// An existing, unchanged [Value] from the database.
68 ///
69 /// You get these when you query an existing [Model][crate::ModelTrait]
70 /// from the database and convert it into an [ActiveModel][crate::ActiveModelTrait].
71 ///
72 /// When you edit it, you can use [set_ne][ActiveValue::set_ne]
73 /// to preserve this "unchanged" state if the new value is the same as the old one.
74 /// Then you can meaningfully use methods like [crate::ActiveModelTrait::is_changed].
75 Unchanged(V),
76 /// An undefined [Value]. Nothing is sent to the database.
77 ///
78 /// When you create a new [ActiveModel][crate::ActiveModelTrait],
79 /// its fields are [NotSet][ActiveValue::NotSet] by default.
80 ///
81 /// This can be useful when:
82 ///
83 /// - You insert a new record and want the database to generate a default value (e.g., an id).
84 /// - In an `UPDATE` statement, you don't want to update some field.
85 NotSet,
86}
87
88/// Defines an not set operation on an [ActiveValue]
89#[deprecated(
90 since = "0.5.0",
91 note = "Please use [`ActiveValue::NotSet`] or [`NotSet`]"
92)]
93#[allow(non_snake_case)]
94pub fn Unset<V>(_: Option<bool>) -> ActiveValue<V>
95where
96 V: Into<Value>,
97{
98 ActiveValue::not_set()
99}
100
101/// Any type that can be converted into an [ActiveValue]
102pub trait IntoActiveValue<V>
103where
104 V: Into<Value>,
105{
106 /// Method to perform the conversion
107 fn into_active_value(self) -> ActiveValue<V>;
108}
109
110impl<V> IntoActiveValue<V> for Option<V>
111where
112 V: IntoActiveValue<V> + Into<Value> + Nullable,
113{
114 fn into_active_value(self) -> ActiveValue<V> {
115 match self {
116 Some(value) => Set(value),
117 None => NotSet,
118 }
119 }
120}
121
122impl<V> IntoActiveValue<Option<V>> for Option<Option<V>>
123where
124 V: IntoActiveValue<V> + Into<Value> + Nullable,
125{
126 fn into_active_value(self) -> ActiveValue<Option<V>> {
127 match self {
128 Some(value) => Set(value),
129 None => NotSet,
130 }
131 }
132}
133
134macro_rules! impl_into_active_value {
135 ($ty: ty) => {
136 impl IntoActiveValue<$ty> for $ty {
137 fn into_active_value(self) -> ActiveValue<$ty> {
138 Set(self)
139 }
140 }
141 };
142}
143
144impl_into_active_value!(bool);
145impl_into_active_value!(i8);
146impl_into_active_value!(i16);
147impl_into_active_value!(i32);
148impl_into_active_value!(i64);
149impl_into_active_value!(u8);
150impl_into_active_value!(u16);
151impl_into_active_value!(u32);
152impl_into_active_value!(u64);
153impl_into_active_value!(f32);
154impl_into_active_value!(f64);
155impl_into_active_value!(&'static str);
156impl_into_active_value!(String);
157impl_into_active_value!(Vec<u8>);
158
159#[cfg(feature = "with-json")]
160#[cfg_attr(docsrs, doc(cfg(feature = "with-json")))]
161impl_into_active_value!(crate::prelude::Json);
162
163#[cfg(feature = "with-chrono")]
164#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
165impl_into_active_value!(crate::prelude::Date);
166
167#[cfg(feature = "with-chrono")]
168#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
169impl_into_active_value!(crate::prelude::Time);
170
171#[cfg(feature = "with-chrono")]
172#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
173impl_into_active_value!(crate::prelude::DateTime);
174
175#[cfg(feature = "with-chrono")]
176#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
177impl_into_active_value!(crate::prelude::DateTimeWithTimeZone);
178
179#[cfg(feature = "with-chrono")]
180#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
181impl_into_active_value!(crate::prelude::DateTimeUtc);
182
183#[cfg(feature = "with-chrono")]
184#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
185impl_into_active_value!(crate::prelude::DateTimeLocal);
186
187#[cfg(feature = "with-rust_decimal")]
188#[cfg_attr(docsrs, doc(cfg(feature = "with-rust_decimal")))]
189impl_into_active_value!(crate::prelude::Decimal);
190
191#[cfg(feature = "with-bigdecimal")]
192#[cfg_attr(docsrs, doc(cfg(feature = "with-bigdecimal")))]
193impl_into_active_value!(crate::prelude::BigDecimal);
194
195#[cfg(feature = "with-uuid")]
196#[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))]
197impl_into_active_value!(crate::prelude::Uuid);
198
199#[cfg(feature = "with-time")]
200#[cfg_attr(docsrs, doc(cfg(feature = "with-time")))]
201impl_into_active_value!(crate::prelude::TimeDate);
202
203#[cfg(feature = "with-time")]
204#[cfg_attr(docsrs, doc(cfg(feature = "with-time")))]
205impl_into_active_value!(crate::prelude::TimeTime);
206
207#[cfg(feature = "with-time")]
208#[cfg_attr(docsrs, doc(cfg(feature = "with-time")))]
209impl_into_active_value!(crate::prelude::TimeDateTime);
210
211#[cfg(feature = "with-time")]
212#[cfg_attr(docsrs, doc(cfg(feature = "with-time")))]
213impl_into_active_value!(crate::prelude::TimeDateTimeWithTimeZone);
214
215#[cfg(feature = "with-ipnetwork")]
216#[cfg_attr(docsrs, doc(cfg(feature = "with-ipnetwork")))]
217impl_into_active_value!(crate::prelude::IpNetwork);
218
219impl<V> Default for ActiveValue<V>
220where
221 V: Into<Value>,
222{
223 /// Create an [ActiveValue::NotSet]
224 fn default() -> Self {
225 Self::NotSet
226 }
227}
228
229impl<V> ActiveValue<V>
230where
231 V: Into<Value>,
232{
233 /// Create an [ActiveValue::Set]
234 pub fn set(value: V) -> Self {
235 Self::Set(value)
236 }
237
238 /// Check if the [ActiveValue] is [ActiveValue::Set]
239 pub fn is_set(&self) -> bool {
240 matches!(self, Self::Set(_))
241 }
242
243 /// Check if the [ActiveValue] is [ActiveValue::Set] and that the inner value
244 /// matches a given predicate.
245 pub fn is_set_and(&self, f: impl FnOnce(&V) -> bool) -> bool {
246 matches!(self, Self::Set(v) if f(v))
247 }
248
249 /// Create an [ActiveValue::Unchanged]
250 pub fn unchanged(value: V) -> Self {
251 Self::Unchanged(value)
252 }
253
254 /// Check if the [ActiveValue] is [ActiveValue::Unchanged]
255 pub fn is_unchanged(&self) -> bool {
256 matches!(self, Self::Unchanged(_))
257 }
258
259 /// Check if the [ActiveValue] is [ActiveValue::Unchanged] and that the inner
260 /// value matches a given predicate.
261 pub fn is_unchanged_and(&self, f: impl FnOnce(&V) -> bool) -> bool {
262 matches!(self, Self::Unchanged(v) if f(v))
263 }
264
265 /// Create an [ActiveValue::NotSet]
266 pub fn not_set() -> Self {
267 Self::default()
268 }
269
270 /// Check if the [ActiveValue] is [ActiveValue::NotSet]
271 pub fn is_not_set(&self) -> bool {
272 matches!(self, Self::NotSet)
273 }
274
275 /// Take ownership of the inner value, also setting self to `NotSet`
276 pub fn take(&mut self) -> Option<V> {
277 match std::mem::take(self) {
278 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => Some(value),
279 ActiveValue::NotSet => None,
280 }
281 }
282
283 /// Get an owned value of the [ActiveValue]
284 ///
285 /// # Panics
286 ///
287 /// Panics if it is [ActiveValue::NotSet]
288 pub fn unwrap(self) -> V {
289 match self {
290 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,
291 ActiveValue::NotSet => panic!("Cannot unwrap ActiveValue::NotSet"),
292 }
293 }
294
295 /// Take ownership of the inner value, consuming self
296 pub fn into_value(self) -> Option<Value> {
297 match self {
298 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => Some(value.into()),
299 ActiveValue::NotSet => None,
300 }
301 }
302
303 /// Wrap the [Value] into a `ActiveValue<Value>`
304 pub fn into_wrapped_value(self) -> ActiveValue<Value> {
305 match self {
306 Self::Set(value) => ActiveValue::set(value.into()),
307 Self::Unchanged(value) => ActiveValue::unchanged(value.into()),
308 Self::NotSet => ActiveValue::not_set(),
309 }
310 }
311
312 /// Reset the value from [ActiveValue::Unchanged] to [ActiveValue::Set],
313 /// leaving [ActiveValue::NotSet] untouched.
314 pub fn reset(&mut self) {
315 *self = match self.take() {
316 Some(value) => ActiveValue::Set(value),
317 None => ActiveValue::NotSet,
318 };
319 }
320
321 /// `Set(value)`, except when [`self.is_unchanged()`][ActiveValue#method.is_unchanged]
322 /// and `value` equals the current [Unchanged][ActiveValue::Unchanged] value.
323 ///
324 /// This is useful when you have an [Unchanged][ActiveValue::Unchanged] value from the database,
325 /// then update it using this method,
326 /// and then use [`.is_unchanged()`][ActiveValue#method.is_unchanged] to see whether it has *actually* changed.
327 ///
328 /// The same nice effect applies to the entire `ActiveModel`.
329 /// You can now meaningfully use [crate::ActiveModelTrait::is_changed][crate::ActiveModelTrait#method.is_changed]
330 /// to see whether are any changes that need to be saved to the database.
331 ///
332 /// ## Examples
333 ///
334 /// ```
335 /// # use sea_orm::ActiveValue;
336 /// #
337 /// let mut value = ActiveValue::Unchanged("old");
338 ///
339 /// // This wouldn't be the case if we used plain `value = Set("old");`
340 /// value.set_ne("old");
341 /// assert!(value.is_unchanged());
342 ///
343 /// // Only when we change the actual `&str` value, it becomes `Set`
344 /// value.set_ne("new");
345 /// assert_eq!(value.is_unchanged(), false);
346 /// assert_eq!(value, ActiveValue::Set("new"));
347 /// ```
348 pub fn set_ne(&mut self, value: V)
349 where
350 V: PartialEq,
351 {
352 match self {
353 ActiveValue::Unchanged(current) if &value == current => {}
354 _ => *self = ActiveValue::Set(value),
355 }
356 }
357
358 /// Alias for [`ActiveValue::set_ne`]. Kept for compatibility.
359 pub fn set_if_not_equals(&mut self, value: V)
360 where
361 V: PartialEq,
362 {
363 self.set_ne(value);
364 }
365
366 /// `Set(value)`, except when [`self.is_unchanged()`][ActiveValue#method.is_unchanged],
367 /// `value` equals the current [Unchanged][ActiveValue::Unchanged] value, and `value`
368 /// does not match a given predicate.
369 ///
370 /// This is useful in the same situations as [`ActiveValue::set_ne`] as
371 /// well as when you want to leave an existing [Set][ActiveValue::Set] value alone
372 /// depending on a condition, such as ensuring a `None` value never replaced an
373 /// existing `Some` value. This can come up when trying to merge two [ActiveValue]s.
374 ///
375 /// ## Examples
376 ///
377 /// ```
378 /// # use sea_orm::ActiveValue;
379 /// #
380 /// let mut value = ActiveValue::Set(Some("old"));
381 ///
382 /// // since Option::is_some(None) == false, we leave the existing set value alone
383 /// value.set_ne_and(None, Option::is_some);
384 /// assert_eq!(value, ActiveValue::Set(Some("old")));
385 ///
386 /// // since Option::is_some(Some("new")) == true, we replace the set value
387 /// value.set_ne_and(Some("new"), Option::is_some);
388 /// assert_eq!(value, ActiveValue::Set(Some("new")));
389 /// ```
390 pub fn set_ne_and(&mut self, value: V, f: impl FnOnce(&V) -> bool)
391 where
392 V: PartialEq,
393 {
394 match self {
395 ActiveValue::Unchanged(current) if &value == current => {}
396 ActiveValue::Set(_) if !f(&value) => {}
397 _ => *self = ActiveValue::Set(value),
398 }
399 }
400
401 /// Alias for [`ActiveValue::set_ne_and`]. Kept for compatibility.
402 pub fn set_if_not_equals_and(&mut self, value: V, f: impl FnOnce(&V) -> bool)
403 where
404 V: PartialEq,
405 {
406 self.set_ne_and(value, f);
407 }
408
409 /// `Set(value)` if [`self.is_not_set()`][ActiveValue#method.is_not_set], no-op otherwise.
410 /// Similar to "null coalescing" or [Option#method.get_or_insert], but without
411 /// returning the inner value if it is set/unchanged.
412 ///
413 /// ## Examples
414 ///
415 /// ```
416 /// # use sea_orm::ActiveValue;
417 /// #
418 /// let mut set_value = ActiveValue::Set(true);
419 /// let mut unchanged_value = ActiveValue::Unchanged(true);
420 /// let mut notset_value = ActiveValue::NotSet;
421 ///
422 /// // since `set_value.is_not_set == false`, we leave the existing set value alone
423 /// set_value.set_if_unset(false);
424 /// assert_eq!(set_value, ActiveValue::Set(true));
425 ///
426 /// // since `set_value.is_not_set == false`, we leave the existing set value alone
427 /// unchanged_value.set_if_unset(false);
428 /// assert_eq!(unchanged_value, ActiveValue::Unchanged(true));
429 ///
430 /// // since `set_value.is_not_set == true`, we fill with the provided value
431 /// notset_value.set_if_unset(false);
432 /// assert_eq!(notset_value, ActiveValue::Set(false));
433 /// ```
434 pub fn set_if_unset(&mut self, value: V) {
435 if let ActiveValue::NotSet = self {
436 *self = ActiveValue::Set(value);
437 }
438 }
439
440 /// `Set(f())` if [`self.is_not_set()`][ActiveValue#method.is_not_set], no-op otherwise.
441 /// Similar to "null coalescing" or [Option#method.get_or_insert_with], but without
442 /// returning the inner value if it is set/unchanged.
443 ///
444 /// This can be useful if the value you want to replace it with is expensive to compute,
445 /// or has side-effects which need to be ran (like logging).
446 ///
447 /// ## Examples
448 ///
449 /// ```
450 /// # use sea_orm::ActiveValue;
451 /// #
452 /// let mut set_value = ActiveValue::Set(true);
453 /// let mut unchanged_value = ActiveValue::Unchanged(true);
454 /// let mut notset_value = ActiveValue::NotSet;
455 ///
456 /// let mut count = 0;
457 /// // since `set_value.is_not_set == false`, we leave the existing set value alone
458 /// set_value.set_if_unset_with(|| {
459 /// count += 1;
460 /// false
461 /// });
462 /// assert_eq!(set_value, ActiveValue::Set(true));
463 ///
464 /// // since `set_value.is_not_set == false`, we leave the existing set value alone
465 /// unchanged_value.set_if_unset_with(|| {
466 /// count += 1;
467 /// false
468 /// });
469 /// assert_eq!(unchanged_value, ActiveValue::Unchanged(true));
470 ///
471 /// // since `set_value.is_not_set == true`, we fill with the result of the provided computation.
472 /// notset_value.set_if_unset_with(|| {
473 /// count += 1;
474 /// false
475 /// });
476 /// assert_eq!(notset_value, ActiveValue::Set(false));
477 ///
478 /// // Only the last closure actually executed.
479 /// assert_eq!(count, 1);
480 /// ```
481 pub fn set_if_unset_with(&mut self, f: impl FnOnce() -> V) {
482 if let ActiveValue::NotSet = self {
483 *self = ActiveValue::Set(f());
484 }
485 }
486
487 /// `Set(V::default())` if [`self.is_not_set()`][ActiveValue#method.is_not_set], no-op otherwise.
488 /// Similar to "null coalescing" or [Option#method.get_or_insert_default], but without
489 /// returning the inner value if it is set/unchanged.
490 ///
491 /// Convenient shorthand for `set_if_unset(Default::default())`.
492 ///
493 /// ## Examples
494 ///
495 /// ```
496 /// # use sea_orm::ActiveValue;
497 /// #
498 /// let mut set_value = ActiveValue::Set(100);
499 /// let mut unchanged_value = ActiveValue::Unchanged(100);
500 /// let mut notset_value = ActiveValue::NotSet;
501 ///
502 /// // since `set_value.is_not_set == false`, we leave the existing set value alone
503 /// set_value.set_if_unset_default();
504 /// assert_eq!(set_value, ActiveValue::Set(100));
505 ///
506 /// // since `set_value.is_not_set == false`, we leave the existing set value alone
507 /// unchanged_value.set_if_unset_default();
508 /// assert_eq!(unchanged_value, ActiveValue::Unchanged(100));
509 ///
510 /// // since `set_value.is_not_set == true`, we fill with the default int (0)
511 /// notset_value.set_if_unset_default();
512 /// assert_eq!(notset_value, ActiveValue::Set(0));
513 /// ```
514 pub fn set_if_unset_default(&mut self)
515 where
516 V: Default,
517 {
518 if let ActiveValue::NotSet = self {
519 *self = ActiveValue::Set(V::default());
520 }
521 }
522
523 /// Get the inner value, unless `self` is [NotSet][ActiveValue::NotSet].
524 ///
525 /// There's also a panicking version: [ActiveValue::as_ref].
526 ///
527 /// ## Examples
528 ///
529 /// ```
530 /// # use sea_orm::ActiveValue;
531 /// #
532 /// assert_eq!(ActiveValue::Unchanged(42).try_as_ref(), Some(&42));
533 /// assert_eq!(ActiveValue::Set(42).try_as_ref(), Some(&42));
534 /// assert_eq!(ActiveValue::NotSet.try_as_ref(), None::<&i32>);
535 /// ```
536 pub fn try_as_ref(&self) -> Option<&V> {
537 match self {
538 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => Some(value),
539 ActiveValue::NotSet => None,
540 }
541 }
542}
543
544impl<V> ActiveValue<Option<V>>
545where
546 V: Into<Value> + Nullable,
547{
548 /// Flatten an `&ActiveValue<Option<V>>` into an `Option<&V>`, folding
549 /// [NotSet][ActiveValue::NotSet] together with the inner [None][Option::None],
550 /// and [Set][ActiveValue::Set] / [Unchanged][ActiveValue::Unchanged] together
551 /// with the inner [Some][Option::Some].
552 ///
553 /// Shorthand for `self.try_as_ref().and_then(Option::as_ref)`. For the owned
554 /// version, see [ActiveValue::into_option].
555 ///
556 /// ```
557 /// use sea_orm::ActiveValue;
558 ///
559 /// let x: ActiveValue<Option<i32>> = ActiveValue::Set(Some(1));
560 /// let y: ActiveValue<Option<i32>> = ActiveValue::Set(None);
561 /// let z: ActiveValue<Option<i32>> = ActiveValue::NotSet;
562 ///
563 /// assert_eq!(x.as_option(), Some(&1));
564 /// assert_eq!(y.as_option(), None);
565 /// assert_eq!(z.as_option(), None);
566 ///
567 /// // composes cleanly with a predicate, on a single line
568 /// assert!(x.as_option().is_some_and(|v| *v == 1));
569 /// ```
570 pub fn as_option(&self) -> Option<&V> {
571 self.try_as_ref().and_then(Option::as_ref)
572 }
573
574 /// Flatten an `ActiveValue<Option<V>>` into an `Option<V>`, folding
575 /// [NotSet][ActiveValue::NotSet] together with the inner [None][Option::None],
576 /// and [Set][ActiveValue::Set] / [Unchanged][ActiveValue::Unchanged] together
577 /// with the inner [Some][Option::Some].
578 ///
579 /// For a borrowing version, see [ActiveValue::as_option].
580 ///
581 /// ```
582 /// use sea_orm::ActiveValue;
583 ///
584 /// let x: ActiveValue<Option<i32>> = ActiveValue::Set(Some(1));
585 /// let y: ActiveValue<Option<i32>> = ActiveValue::Set(None);
586 /// let z: ActiveValue<Option<i32>> = ActiveValue::NotSet;
587 ///
588 /// assert_eq!(x.into_option(), Some(1));
589 /// assert_eq!(y.into_option(), None);
590 /// assert_eq!(z.into_option(), None);
591 /// ```
592 pub fn into_option(self) -> Option<V> {
593 match self {
594 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,
595 ActiveValue::NotSet => None,
596 }
597 }
598}
599
600impl<V> std::convert::AsRef<V> for ActiveValue<V>
601where
602 V: Into<Value>,
603{
604 /// # Panics
605 ///
606 /// Panics if it is [ActiveValue::NotSet].
607 ///
608 /// See [ActiveValue::try_as_ref] for a fallible non-panicking version.
609 fn as_ref(&self) -> &V {
610 match self {
611 ActiveValue::Set(value) | ActiveValue::Unchanged(value) => value,
612 ActiveValue::NotSet => panic!("Cannot borrow ActiveValue::NotSet"),
613 }
614 }
615}
616
617impl<V> PartialEq for ActiveValue<V>
618where
619 V: Into<Value> + std::cmp::PartialEq,
620{
621 fn eq(&self, other: &Self) -> bool {
622 match (self, other) {
623 (ActiveValue::Set(l), ActiveValue::Set(r)) => l == r,
624 (ActiveValue::Unchanged(l), ActiveValue::Unchanged(r)) => l == r,
625 (ActiveValue::NotSet, ActiveValue::NotSet) => true,
626 _ => false,
627 }
628 }
629}
630
631impl<V> From<ActiveValue<V>> for ActiveValue<Option<V>>
632where
633 V: Into<Value> + Nullable,
634{
635 fn from(value: ActiveValue<V>) -> Self {
636 match value {
637 ActiveValue::Set(value) => ActiveValue::set(Some(value)),
638 ActiveValue::Unchanged(value) => ActiveValue::unchanged(Some(value)),
639 ActiveValue::NotSet => ActiveValue::not_set(),
640 }
641 }
642}