pub struct PluginContext {
pub stage: ExecutionStage,
pub sql: String,
pub parameters: Vec<Value>,
pub started_at: Option<Instant>,
pub elapsed: Option<Duration>,
pub affected_rows: Option<usize>,
pub metadata: HashMap<String, Value>,
}Expand description
插件上下文(携带操作信息)
Fields§
§stage: ExecutionStage执行阶段
sql: StringSQL 语句(可被插件修改)
parameters: Vec<Value>绑定参数
started_at: Option<Instant>执行开始时间(用于慢查询检测)
elapsed: Option<Duration>执行耗时(After 阶段才有)
affected_rows: Option<usize>影响行数(After 阶段才有)
metadata: HashMap<String, Value>自定义元数据
Implementations§
Source§impl PluginContext
impl PluginContext
Sourcepub fn new(stage: ExecutionStage, sql: impl Into<String>) -> Self
pub fn new(stage: ExecutionStage, sql: impl Into<String>) -> Self
创建上下文
Sourcepub fn with_parameters(self, params: Vec<Value>) -> Self
pub fn with_parameters(self, params: Vec<Value>) -> Self
设置参数
Sourcepub fn with_start_time(self, instant: Instant) -> Self
pub fn with_start_time(self, instant: Instant) -> Self
设置开始时间
Sourcepub fn with_elapsed(self, elapsed: Duration) -> Self
pub fn with_elapsed(self, elapsed: Duration) -> Self
设置耗时
Sourcepub fn with_affected_rows(self, rows: usize) -> Self
pub fn with_affected_rows(self, rows: usize) -> Self
设置影响行数
Sourcepub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
pub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
添加元数据
Sourcepub fn get_metadata(&self, key: &str) -> Option<&Value>
pub fn get_metadata(&self, key: &str) -> Option<&Value>
获取元数据
Trait Implementations§
Source§impl Clone for PluginContext
impl Clone for PluginContext
Source§fn clone(&self) -> PluginContext
fn clone(&self) -> PluginContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PluginContext
impl RefUnwindSafe for PluginContext
impl Send for PluginContext
impl Sync for PluginContext
impl Unpin for PluginContext
impl UnsafeUnpin for PluginContext
impl UnwindSafe for PluginContext
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