Skip to content

Commit

Permalink
Provide further exaplanation for
Browse files Browse the repository at this point in the history
p�[200pub struct ActiveValue<V>

Add a code snippet for a simple example
  • Loading branch information
charleschege committed Oct 31, 2021
1 parent bb83a6d commit 30814f0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/entity/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ use async_trait::async_trait;
use sea_query::{Nullable, ValueTuple};
use std::fmt::Debug;

/// Defines a value from an ActiveModel and its state
/// Defines a value from an ActiveModel and its state.
/// The field `value` takes in an [Option] type where `Option::Some(V)` , with `V` holding
/// the value that operations like `UPDATE` are being performed on and
/// the `state` field is either `ActiveValueState::Set` or `ActiveValueState::Unchanged`.
/// [Option::None] in the `value` field indicates no value being performed by an operation
/// and that the `state` field of the [ActiveValue] is set to `ActiveValueState::Unset` .
/// #### Example snippet
/// ```no_run
/// // The code snipped below does an UPDATE operation on a [ActiveValue]
/// // yielding the the SQL statement ` r#"UPDATE "fruit" SET "name" = 'Orange' WHERE "fruit"."id" = 1"# `
///
/// use crate::tests_cfg::{cake, fruit};
/// use crate::{entity::*, query::*, DbBackend};
///
/// Update::one(fruit::ActiveModel {
/// id: ActiveValue::set(1),
/// name: ActiveValue::set("Orange".to_owned()),
/// cake_id: ActiveValue::unset(),
/// })
/// .build(DbBackend::Postgres)
/// .to_string();
/// ```
#[derive(Clone, Debug, Default)]
pub struct ActiveValue<V>
where
Expand Down

0 comments on commit 30814f0

Please sign in to comment.