pub struct Row {
pub table: Option<String>,
pub primary_keys: Vec<String>,
pub data: HashMap<String, Value>,
pub changes: HashSet<String>,
}Expand description
Row:携带表名、主键名、数据和变更追踪
Fields§
§table: Option<String>表名
primary_keys: Vec<String>主键字段名列表(默认 ["id"])
data: HashMap<String, Value>数据字段
changes: HashSet<String>变更追踪:记录哪些字段被修改过
Implementations§
Source§impl Row
impl Row
Sourcepub fn primary_key(self, key: impl Into<String>) -> Self
pub fn primary_key(self, key: impl Into<String>) -> Self
设置主键字段
ⓘ
Row::table("user").primary_key("uid")Sourcepub fn primary_keys(self, keys: &[&str]) -> Self
pub fn primary_keys(self, keys: &[&str]) -> Self
Sourcepub fn id<V: Into<Value>>(self, id: V) -> Self
pub fn id<V: Into<Value>>(self, id: V) -> Self
快捷设置主键值(取 primary_keys[0])
ⓘ
Row::table("user").id(123)Sourcepub fn set<V: Into<Value>>(&mut self, key: &str, value: V) -> &mut Self
pub fn set<V: Into<Value>>(&mut self, key: &str, value: V) -> &mut Self
设置字段值
ⓘ
row.set("name", "Alice")
.set("age", 25);Sourcepub fn get_as<'a, T: Deserialize<'a>>(&'a self, key: &str) -> Option<T>
pub fn get_as<'a, T: Deserialize<'a>>(&'a self, key: &str) -> Option<T>
获取字段值并反序列化
ⓘ
let name: String = row.get_as("name").unwrap();Sourcepub fn mark_all_changed(&mut self)
pub fn mark_all_changed(&mut self)
标记所有字段为已修改
Sourcepub fn detect_id_kind(&self) -> Option<IdKind>
pub fn detect_id_kind(&self) -> Option<IdKind>
自动检测主键值的 IdKind(UUID / i64 / 字符串等)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Row
impl<'de> Deserialize<'de> for Row
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Row
impl RefUnwindSafe for Row
impl Send for Row
impl Sync for Row
impl Unpin for Row
impl UnsafeUnpin for Row
impl UnwindSafe for Row
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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