pub enum DbFieldValue {
Auto,
Value(DbValue),
}db only.Expand description
Represents a value for a field in the database.
This enum is used to indicate whether a field’s value should be explicitly included in a query or automatically generated by the database.
DbFieldValue::Auto: The field’s value will be automatically generated by the database and not included in the query.DbFieldValue::Value: A specific value is provided and included in the query.
§Examples
Using DbFieldValue to represent a field value in an insert operation:
use cot::db::{DbFieldValue, DbValue};
// Simulate a database field with a specific value
let value_field = DbFieldValue::Value(DbValue::Int(Some(42)));
assert!(value_field.is_value());
assert!(!value_field.is_auto());
// Simulate a database field with an auto-incremented value
let auto_field = DbFieldValue::Auto;
assert!(auto_field.is_auto());
assert!(!auto_field.is_value());
// Extract the value from a DbFieldValue::Value variant
if let DbFieldValue::Value(val) = value_field {
println!("Field value: {:?}", val);
}
// Attempting to unwrap an auto-generated field will panic:
// auto_field.unwrap_value(); // This would panic!Variants§
Auto
The value should be automatically generated by the database and not included in the query.
§Examples
use cot::db::{DbFieldValue, DbValue};
let auto_field = DbFieldValue::Auto;
assert!(auto_field.is_auto());Value(DbValue)
A value that should be included in the query.
§Examples
use cot::db::{DbFieldValue, DbValue};
let value_field = DbFieldValue::Value(DbValue::Int(Some(42)));
assert!(value_field.is_value());
assert_eq!(value_field.unwrap_value(), DbValue::Int(Some(42)));Implementations§
Source§impl DbFieldValue
impl DbFieldValue
Sourcepub fn is_auto(&self) -> bool
pub fn is_auto(&self) -> bool
Returns true if the field value is automatically generated by the database.
§Examples
use cot::db::DbFieldValue;
let auto_field = DbFieldValue::Auto;
assert!(auto_field.is_auto());Sourcepub fn is_value(&self) -> bool
pub fn is_value(&self) -> bool
Returns true if the field value is explicitly provided and included in the query.
§Examples
use cot::db::{DbFieldValue, DbValue};
let value_field = DbFieldValue::Value(DbValue::Int(Some(42)));
assert!(value_field.is_value());Sourcepub fn unwrap_value(self) -> DbValue
pub fn unwrap_value(self) -> DbValue
Returns the value of the field if it is explicitly provided and included in the query.
§Panics
This method will panic if the field value is automatically generated by the database.
§Examples
use cot::db::{DbFieldValue, DbValue};
let value_field = DbFieldValue::Value(DbValue::Int(Some(42)));
assert_eq!(value_field.unwrap_value(), DbValue::Int(Some(42)));Sourcepub fn expect_value(self, message: &str) -> DbValue
pub fn expect_value(self, message: &str) -> DbValue
Returns the value of the field if it is explicitly provided and included in the query.
§Panics
This method will panic with given message if the field value is automatically generated by the database.
§Examples
use cot::db::{DbFieldValue, DbValue};
let value_field = DbFieldValue::Value(DbValue::Int(Some(42)));
assert_eq!(
value_field.expect_value("expected value"),
DbValue::Int(Some(42))
);Trait Implementations§
Source§impl Clone for DbFieldValue
impl Clone for DbFieldValue
Source§fn clone(&self) -> DbFieldValue
fn clone(&self) -> DbFieldValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DbFieldValue
impl Debug for DbFieldValue
Source§impl PartialEq for DbFieldValue
impl PartialEq for DbFieldValue
impl StructuralPartialEq for DbFieldValue
Auto Trait Implementations§
impl Freeze for DbFieldValue
impl RefUnwindSafe for DbFieldValue
impl Send for DbFieldValue
impl Sync for DbFieldValue
impl Unpin for DbFieldValue
impl UnwindSafe for DbFieldValue
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 moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
db only.