Trait rbatis::plugin::intercept::Intercept

source ·
pub trait Intercept: Send + Sync + Debug {
    // Provided methods
    fn name(&self) -> &str { ... }
    fn before<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
        &'life0 self,
        _task_id: i64,
        _rb: &'life1 dyn Executor,
        _sql: &'life2 mut String,
        _args: &'life3 mut Vec<Value>,
        _result: ResultType<&'life4 mut Result<ExecResult, Error>, &'life5 mut Result<Vec<Value>, Error>>
    ) -> Pin<Box<dyn Future<Output = Result<Option<bool>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             'life5: 'async_trait { ... }
    fn after<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
        &'life0 self,
        _task_id: i64,
        _rb: &'life1 dyn Executor,
        _sql: &'life2 mut String,
        _args: &'life3 mut Vec<Value>,
        _result: ResultType<&'life4 mut Result<ExecResult, Error>, &'life5 mut Result<Vec<Value>, Error>>
    ) -> Pin<Box<dyn Future<Output = Result<Option<bool>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             'life5: 'async_trait { ... }
}
Expand description

sql intercept example:

use rbatis::Error;
use rbatis::executor::Executor;
use rbatis::intercept::{Intercept, ResultType};
use rbdc::db::ExecResult;
use rbs::Value;

#[derive(Debug)]
pub struct ReturningIdPlugin{}

#[rbatis::async_trait]
impl Intercept for ReturningIdPlugin {
    async fn before(
        &self,
        _task_id: i64,
        rb: &dyn Executor,
        sql: &mut String,
        args: &mut Vec<Value>,
        result: ResultType<&mut Result<ExecResult, Error>, &mut Result<Vec<Value>, Error>>,
    ) -> Result<Option<bool>, Error> {
        Ok(Some(true))
    }
}

Provided Methods§

source

fn name(&self) -> &str

source

fn before<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, _task_id: i64, _rb: &'life1 dyn Executor, _sql: &'life2 mut String, _args: &'life3 mut Vec<Value>, _result: ResultType<&'life4 mut Result<ExecResult, Error>, &'life5 mut Result<Vec<Value>, Error>> ) -> Pin<Box<dyn Future<Output = Result<Option<bool>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

task_id maybe is conn_id or tx_id, is_prepared_sql = !args.is_empty(),

if return None will be return result if return Some(true) will be run next intercept if return Some(false) will be break

source

fn after<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>( &'life0 self, _task_id: i64, _rb: &'life1 dyn Executor, _sql: &'life2 mut String, _args: &'life3 mut Vec<Value>, _result: ResultType<&'life4 mut Result<ExecResult, Error>, &'life5 mut Result<Vec<Value>, Error>> ) -> Pin<Box<dyn Future<Output = Result<Option<bool>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, 'life5: 'async_trait,

task_id maybe is conn_id or tx_id, is_prepared_sql = !args.is_empty(), if return Ok(false) will be return data. return Ok(true) will run next

Implementors§