[][src]Struct rbatis::rbatis::Rbatis

pub struct Rbatis {
    pub pool: OnceCell<DBPool>,
    pub runtime_expr: ExprRuntime,
    pub runtime_py: PyRuntime,
    pub tx_manager: Arc<TxManager>,
    pub page_plugin: Box<dyn PagePlugin>,
    pub sql_intercepts: Vec<Box<dyn SqlIntercept>>,
    pub logic_plugin: Option<Box<dyn LogicDelete>>,
    pub log_plugin: Arc<Box<dyn LogPlugin>>,
}

rbatis engine

Fields

pool: OnceCell<DBPool>runtime_expr: ExprRuntimeruntime_py: PyRuntimetx_manager: Arc<TxManager>page_plugin: Box<dyn PagePlugin>sql_intercepts: Vec<Box<dyn SqlIntercept>>logic_plugin: Option<Box<dyn LogicDelete>>log_plugin: Arc<Box<dyn LogPlugin>>

Implementations

impl Rbatis[src]

pub fn new() -> Self[src]

create an Rbatis

pub fn new_with_opt(option: RbatisOption) -> Self[src]

new Rbatis from Option

pub fn new_wrapper(&self) -> Wrapper[src]

try return an new wrapper,if not call the link() method,it will be panic!

pub fn new_wrapper_table<T>(&self) -> Wrapper where
    T: CRUDEnable
[src]

try return an new wrapper and set table formats,if not call the link() method,it will be panic!

link pool

link pool by DBPoolOptions for example: let mut opt = PoolOptions::new(); opt.max_size = 20; rb.link_opt("mysql://root:123456@localhost:3306/test", &opt).await.unwrap();

link pool by DBConnectOption and DBPoolOptions for example: let db_cfg=DBConnectOption::from("mysql://root:123456@localhost:3306/test")?; rb.link_cfg(&db_cfg,PoolOptions::new());

pub fn set_log_plugin<T>(&mut self, arg: T) where
    T: LogPlugin + 'static, 
[src]

pub fn set_logic_plugin<T>(&mut self, arg: Option<T>) where
    T: LogicDelete + 'static, 
[src]

pub fn set_page_plugin<T>(&mut self, arg: T) where
    T: PagePlugin + 'static, 
[src]

pub fn add_sql_intercept<T>(&mut self, arg: T) where
    T: SqlIntercept + 'static, 
[src]

pub fn set_sql_intercepts<T>(&mut self, arg: Vec<Box<dyn SqlIntercept>>)[src]

pub fn get_pool(&self) -> Result<&DBPool, Error>[src]

get conn pool

pub fn driver_type(&self) -> Result<DriverType, Error>[src]

get driver type

pub async fn begin_tx_defer(
    &self,
    when_drop_commit: bool
) -> Result<TxGuard, Error>
[src]

begin tx,if TxGuard Drop, tx will be commit(when_drop_commit==true) or rollback(when_drop_commit==false) tx_id must be 'tx:'+id,this method default is 'tx:'+uuid for example: let guard = RB.begin_tx_defer(true).await?; let v: serde_json::Value = RB.fetch(&guard.tx_id, "SELECT count(1) FROM biz_activity;").await?;

pub async fn begin_tx(&self) -> Result<String, Error>[src]

begin tx,for new conn,return (String(context_id/tx_id),u64) tx_id must be 'tx:'+id,this method default is 'tx:'+uuid

for example: let tx_id = rb.begin_tx().await.unwrap(); let v: serde_json::Value = rb.fetch(&tx_id, "SELECT count(1) FROM biz_activity;").await.unwrap();

pub async fn begin_defer(
    &self,
    context_id: &str,
    when_drop_commit: bool
) -> Result<TxGuard, Error>
[src]

begin tx,if TxGuard Drop, tx will be commit(when_drop_commit==true) or rollback(when_drop_commit==false) arg context_id must be 'tx:***'

for example: let context_id = "tx:1"; let tx_id = rb.begin_defer(context_id,true).await.unwrap(); let v: serde_json::Value = rb.fetch(&tx_id, "SELECT count(1) FROM biz_activity;").await.unwrap();

pub async fn begin(&self, context_id: &str) -> Result<String, Error>[src]

begin tx,for new conn,return <u64(tx num),Error> arg context_id must be 'tx:***'

for example: let context_id = "tx:1"; rb.begin(context_id).await.unwrap(); let v: serde_json::Value = rb.fetch(context_id, "SELECT count(1) FROM biz_activity;").await.unwrap(); println!("{}", v.clone()); rb.commit(context_id).await.unwrap();

pub async fn commit(&self, context_id: &str) -> Result<String, Error>[src]

commit tx,and return conn,return <u64(tx num),Error>

pub async fn rollback(&self, context_id: &str) -> Result<String, Error>[src]

rollback tx,and return conn,return <u64(tx num),Error>

pub async fn fetch<T>(&self, context_id: &str, sql: &str) -> Result<T, Error> where
    T: DeserializeOwned
[src]

fetch result(row sql)

for example: let v: serde_json::Value = rb.fetch(context_id, "SELECT count(1) FROM biz_activity;").await?;

pub async fn exec(
    &self,
    context_id: &str,
    sql: &str
) -> Result<DBExecResult, Error>
[src]

exec sql(row sql) for example: rb.exec("", "CREATE TABLE biz_uuid( id uuid, name VARCHAR, PRIMARY KEY(id));").await;

pub async fn fetch_prepare<T>(
    &self,
    context_id: &str,
    sql: &str,
    args: &Vec<Value>
) -> Result<T, Error> where
    T: DeserializeOwned
[src]

fetch result(prepare sql)

for example: let v = RB.fetch_prepare::("", "SELECT count(1) FROM biz_activity where delete_flag = ?;", &vec![json!(1)]).await;

pub async fn exec_prepare(
    &self,
    context_id: &str,
    sql: &str,
    args: &Vec<Value>
) -> Result<DBExecResult, Error>
[src]

exec sql(prepare sql)

for example: let v = RB.exec_prepare::("", "SELECT count(1) FROM biz_activity where delete_flag = ?;", &vec![json!(1)]).await;

pub async fn fetch_prepare_wrapper<T>(
    &self,
    context_id: &str,
    w: &Wrapper
) -> Result<T, Error> where
    T: DeserializeOwned
[src]

fetch data by a wrapper

for example: let name = "test"; let w = RB.new_wrapper() .push_sql("SELECT count(1) FROM biz_activity WHERE ") .r#in("delete_flag", &[0, 1]) .and() .ne("delete_flag", -1) .do_if(!name.is_empty(), |w| w.and().like("name", name)) .check().unwrap(); let r: serde_json::Value = rb.fetch_prepare_wrapper("", &w).await.unwrap();

pub async fn exec_prepare_wrapper(
    &self,
    context_id: &str,
    w: &Wrapper
) -> Result<DBExecResult, Error>
[src]

exec sql by a wrapper

pub async fn py_fetch<T, Ser>(
    &self,
    context_id: &str,
    py: &str,
    arg: &Ser
) -> Result<T, Error> where
    T: DeserializeOwned,
    Ser: Serialize + Send + Sync
[src]

fetch query result(prepare sql) for example:

     let py = r#"
 SELECT * FROM biz_activity
WHERE delete_flag = #{delete_flag}
 if name != null:
   AND name like #{name+'%'}
 if ids != null:
   AND id in (
   trim ',':
      for item in ids:
        #{item},
   )"#;
     let data: serde_json::Value = rb.py_fetch("", py, &json!({   "delete_flag": 1 })).await.unwrap();

pub async fn py_exec<Ser>(
    &self,
    context_id: &str,
    py: &str,
    arg: &Ser
) -> Result<DBExecResult, Error> where
    Ser: Serialize + Send + Sync
[src]

exec sql(prepare sql) for example:

     let py = r#"
 SELECT * FROM biz_activity
WHERE delete_flag = #{delete_flag}
 if name != null:
   AND name like #{name+'%'}
 if ids != null:
   AND id in (
   trim ',':
      for item in ids:
        #{item},
   )"#;
     let data: u64 = rb.py_exec("", py, &json!({   "delete_flag": 1 })).await.unwrap();

pub async fn fetch_page<T>(
    &self,
    context_id: &str,
    sql: &str,
    args: &Vec<Value>,
    page_request: &dyn IPageRequest
) -> Result<Page<T>, Error> where
    T: DeserializeOwned + Serialize + Send + Sync
[src]

fetch page result(prepare sql)

pub async fn py_fetch_page<T, Ser>(
    &self,
    context_id: &str,
    py: &str,
    arg: &Ser,
    page: &dyn IPageRequest
) -> Result<Page<T>, Error> where
    T: DeserializeOwned + Serialize + Send + Sync,
    Ser: Serialize + Send + Sync
[src]

fetch result(prepare sql)

Trait Implementations

impl CRUD for Rbatis[src]

pub fn save<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    entity: &'life2 T
) -> Pin<Box<dyn Future<Output = Result<DBExecResult>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

save one entity to database

pub fn save_batch<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    args: &'life2 [T]
) -> Pin<Box<dyn Future<Output = Result<DBExecResult>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

save batch makes many value into only one sql. make sure your data not to long!

for Example: rb.save_batch(&vec![activity]); [rbatis] Exec ==> INSERT INTO biz_activity (id,name,version) VALUES ( ? , ? , ?),( ? , ? , ?)

pub fn remove_by_wrapper<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    w: &'life2 Wrapper
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

remove database record by a wrapper

pub fn remove_by_id<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    id: &'life2 T::IdType
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

remove database record by id

pub fn remove_batch_by_id<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    ids: &'life2 [T::IdType]
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

remove batch id for Example : rb.remove_batch_by_id::(&["1".to_string(),"2".to_string()]).await; [rbatis] Exec ==> DELETE FROM biz_activity WHERE id IN ( ? , ? )

pub fn update_by_wrapper<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    arg: &'life2 T,
    w: &'life3 Wrapper,
    update_null_value: bool
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
    Self: 'async_trait, 
[src]

update arg by wrapper

pub fn update_by_id<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    arg: &'life2 T
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

update database record by id

pub fn update_batch_by_id<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    args: &'life2 [T]
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

remove batch database record by args

pub fn fetch_by_wrapper<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    w: &'life2 Wrapper
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record by a wrapper

pub fn fetch_by_id<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    id: &'life2 T::IdType
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record by id

pub fn list_by_wrapper<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    w: &'life2 Wrapper
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record list by a wrapper

pub fn list<'life0, 'life1, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record list

pub fn list_by_ids<'life0, 'life1, 'life2, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    ids: &'life2 [T::IdType]
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record list by a id array

pub fn fetch_page_by_wrapper<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
    &'life0 self,
    context_id: &'life1 str,
    w: &'life2 Wrapper,
    page: &'life3 dyn IPageRequest
) -> Pin<Box<dyn Future<Output = Result<Page<T>>> + Send + 'async_trait>> where
    T: CRUDEnable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
    Self: 'async_trait, 
[src]

fetch page database record list by a wrapper

impl Debug for Rbatis[src]

impl Default for Rbatis[src]

impl Drop for Rbatis[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,