pub struct TimestampBehavior {
pub created_field: &'static str,
pub updated_field: &'static str,
}Expand description
自动填充时间戳 Behavior
§示例
use sz_orm_model::behaviors::{Behavior, TimestampBehavior};
use sz_orm_model::hooks::HookContext;
use sz_orm_model::Value;
use std::collections::HashMap;
let b = TimestampBehavior::new("created_at", "updated_at");
let ctx = HookContext::default().with_timestamp(1700000000);
let mut attrs = HashMap::new();
b.before_insert(&ctx, &mut attrs).unwrap();
assert_eq!(attrs.get("created_at"), Some(&Value::I64(1700000000)));
assert_eq!(attrs.get("updated_at"), Some(&Value::I64(1700000000)));Fields§
§created_field: &'static str创建时间字段名(默认 “created_at”)
updated_field: &'static str更新时间字段名(默认 “updated_at”)
Implementations§
Trait Implementations§
Source§impl Behavior for TimestampBehavior
impl Behavior for TimestampBehavior
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 TimestampBehavior
impl RefUnwindSafe for TimestampBehavior
impl Send for TimestampBehavior
impl Sync for TimestampBehavior
impl Unpin for TimestampBehavior
impl UnsafeUnpin for TimestampBehavior
impl UnwindSafe for TimestampBehavior
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