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

pub struct Rbatis {
    pub pool: OnceCell<DBPool>,
    pub runtime_expr: RExprRuntime,
    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>>,
    pub version_lock_plugin: Option<Box<dyn VersionLockPlugin>>,
}

rbatis engine

Fields

pool: OnceCell<DBPool>runtime_expr: RExprRuntimeruntime_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>>version_lock_plugin: Option<Box<dyn VersionLockPlugin>>

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: CRUDTable
[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(&mut self, arg: impl LogPlugin + 'static)[src]

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

pub fn set_page_plugin(&mut self, arg: impl PagePlugin + 'static)[src]

pub fn add_sql_intercept(&mut self, arg: impl SqlIntercept + 'static)[src]

pub fn set_sql_intercepts(&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 py_fetch<T, Arg>(
    &self,
    context_id: &str,
    py_sql: &str,
    arg: &Arg
) -> Result<T, Error> where
    T: DeserializeOwned,
    Arg: 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<Arg>(
    &self,
    context_id: &str,
    py_sql: &str,
    arg: &Arg
) -> Result<DBExecResult, Error> where
    Arg: 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, Arg>(
    &self,
    context_id: &str,
    py_sql: &str,
    arg: &Arg,
    page_request: &dyn IPageRequest
) -> Result<Page<T>, Error> where
    T: DeserializeOwned + Serialize + Send + Sync,
    Arg: Serialize + Send + Sync
[src]

fetch result(prepare sql)

pub fn is_debug_mode(&self) -> bool[src]

is debug mode

Trait Implementations

impl CRUD for Rbatis[src]

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

save by wrapper

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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

save one entity to database

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: CRUDTable,
    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 do not too long!

for Example: rb.save_batch(“”,&vec![activity]); [rbatis] Exec ==> insert into biz_activity (id,name,version) values ( ? , ? , ?),( ? , ? , ?)

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

save batch slice makes many value into many sql. make sure your slice_len do not too long! slice_len = 0 : save all data slice_len != 0 : save data with slice_len everytime until save all data

for Example: rb.save_batch_slice(“”,&vec![activity],0); [rbatis] Exec ==> insert into biz_activity (id,name,version) values ( ? , ? , ?),( ? , ? , ?)

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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

remove database record by a wrapper

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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

remove database record by id

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: CRUDTable,
    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 ( ? , ? )

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

update arg by wrapper

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

update database record by id

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

remove batch database record by args

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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record by a wrapper

fn fetch_count_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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

count database record by a wrapper

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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record by id

fn fetch_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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record list by a wrapper

fn fetch_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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record list for all

fn fetch_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: CRUDTable,
    T: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: 'async_trait, 
[src]

fetch database record list by a id array

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: CRUDTable,
    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

impl !RefUnwindSafe for Rbatis

impl Send for Rbatis

impl Sync for Rbatis

impl Unpin for Rbatis

impl !UnwindSafe for Rbatis

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>,