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§
Source§impl BlameableBehavior
impl BlameableBehavior
Sourcepub fn new(
created_field: &'static str,
updated_field: &'static str,
) -> BlameableBehavior
pub fn new( created_field: &'static str, updated_field: &'static str, ) -> BlameableBehavior
创建 BlameableBehavior
Sourcepub fn default_fields() -> BlameableBehavior
pub fn default_fields() -> BlameableBehavior
使用默认字段名(created_by/updated_by)
Trait Implementations§
Source§impl Behavior for BlameableBehavior
impl Behavior for BlameableBehavior
Source§fn before_insert(
&self,
ctx: &HookContext,
attrs: &mut HashMap<String, Value>,
) -> Result<(), DbError>
fn before_insert( &self, ctx: &HookContext, attrs: &mut HashMap<String, Value>, ) -> Result<(), DbError>
在 insert 前触发(默认空实现)
Source§fn before_update(
&self,
ctx: &HookContext,
attrs: &mut HashMap<String, Value>,
) -> Result<(), DbError>
fn before_update( &self, ctx: &HookContext, attrs: &mut HashMap<String, Value>, ) -> Result<(), DbError>
在 update 前触发(默认空实现)
Source§fn before_delete(
&self,
_ctx: &HookContext,
_attrs: &mut HashMap<String, Value>,
) -> Result<(), DbError>
fn before_delete( &self, _ctx: &HookContext, _attrs: &mut HashMap<String, Value>, ) -> Result<(), DbError>
在 delete 前触发(默认空实现)
Source§fn after_find(
&self,
_ctx: &HookContext,
_attrs: &mut HashMap<String, Value>,
) -> Result<(), DbError>
fn after_find( &self, _ctx: &HookContext, _attrs: &mut HashMap<String, Value>, ) -> Result<(), DbError>
在 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
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