pub struct BlameableBehavior {
pub created_field: &'static str,
pub updated_field: &'static str,
}Expand description
自动填充操作人 Behavior
§示例
use sz_orm_model::behaviors::{Behavior, BlameableBehavior};
use sz_orm_model::hooks::HookContext;
use sz_orm_model::Value;
use std::collections::HashMap;
let b = BlameableBehavior::new("created_by", "updated_by");
let ctx = HookContext::default().with_operator(42);
let mut attrs = HashMap::new();
b.before_insert(&ctx, &mut attrs).unwrap();
assert_eq!(attrs.get("created_by"), Some(&Value::I64(42)));
assert_eq!(attrs.get("updated_by"), Some(&Value::I64(42)));Fields§
§created_field: &'static str创建人字段名(默认 “created_by”)
updated_field: &'static str更新人字段名(默认 “updated_by”)
Implementations§
Trait Implementations§
Source§impl Behavior for BlameableBehavior
impl Behavior for BlameableBehavior
Source§fn before_insert(
&self,
ctx: &HookContext,
attrs: &mut HashMap<String, Value>,
) -> BehaviorResult<()>
fn before_insert( &self, ctx: &HookContext, attrs: &mut HashMap<String, Value>, ) -> BehaviorResult<()>
在 insert 前触发(默认空实现)
Source§fn before_update(
&self,
ctx: &HookContext,
attrs: &mut HashMap<String, Value>,
) -> BehaviorResult<()>
fn before_update( &self, ctx: &HookContext, attrs: &mut HashMap<String, Value>, ) -> BehaviorResult<()>
在 update 前触发(默认空实现)
Source§fn before_delete(
&self,
_ctx: &HookContext,
_attrs: &mut HashMap<String, Value>,
) -> BehaviorResult<()>
fn before_delete( &self, _ctx: &HookContext, _attrs: &mut HashMap<String, Value>, ) -> BehaviorResult<()>
在 delete 前触发(默认空实现)
Source§fn after_find(
&self,
_ctx: &HookContext,
_attrs: &mut HashMap<String, Value>,
) -> BehaviorResult<()>
fn after_find( &self, _ctx: &HookContext, _attrs: &mut HashMap<String, Value>, ) -> BehaviorResult<()>
在 find 后触发(默认空实现,可用于字段后处理)
Auto Trait Implementations§
impl Freeze for BlameableBehavior
impl RefUnwindSafe for BlameableBehavior
impl Send for BlameableBehavior
impl Sync for BlameableBehavior
impl Unpin for BlameableBehavior
impl UnsafeUnpin for BlameableBehavior
impl UnwindSafe for BlameableBehavior
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