pub struct ChangeTracker { /* private fields */ }Expand description
变更跟踪器
管理多个实体的状态,提供批量变更检测和变更集生成。
Implementations§
Source§impl ChangeTracker
impl ChangeTracker
pub fn new() -> Self
Sourcepub fn track(
&mut self,
table: &str,
id: &str,
current: HashMap<String, Value>,
state: EntityState,
)
pub fn track( &mut self, table: &str, id: &str, current: HashMap<String, Value>, state: EntityState, )
跟踪实体
如果状态为 Unchanged,会保存当前值作为原始值快照。
如果状态为 Modified,会保留之前的原始值快照。
Sourcepub fn mark_unchanged(
&mut self,
table: &str,
id: &str,
entity: HashMap<String, Value>,
)
pub fn mark_unchanged( &mut self, table: &str, id: &str, entity: HashMap<String, Value>, )
标记为未变更(从数据库加载后调用)
Sourcepub fn mark_deleted(&mut self, table: &str, id: &str)
pub fn mark_deleted(&mut self, table: &str, id: &str)
标记为已删除
Sourcepub fn detect_changes(&mut self)
pub fn detect_changes(&mut self)
自动检测变更
遍历所有 Unchanged 实体,如果 current 与 original 不同,自动转为 Modified。
Sourcepub fn get_pending_changes(&self) -> Vec<&EntityEntry>
pub fn get_pending_changes(&self) -> Vec<&EntityEntry>
获取所有待提交的变更
Sourcepub fn get_pending_changes_by_table(&self) -> HashMap<String, Vec<&EntityEntry>>
pub fn get_pending_changes_by_table(&self) -> HashMap<String, Vec<&EntityEntry>>
按表分组获取待提交的变更
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
待提交的变更数量
Sourcepub fn accept_changes(&mut self)
pub fn accept_changes(&mut self)
清除所有跟踪状态(SaveChanges 成功后调用)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChangeTracker
impl RefUnwindSafe for ChangeTracker
impl Send for ChangeTracker
impl Sync for ChangeTracker
impl Unpin for ChangeTracker
impl UnsafeUnpin for ChangeTracker
impl UnwindSafe for ChangeTracker
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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