Skip to content

Releases: rbatis/rbatis

v4.6.13

03 Dec 03:31

Choose a tag to compare

what changes?

  • Support for temporarily replacing the interceptor list
    for example:
/// Mock intercept that just prints SQL
#[derive(Debug)]
pub struct MockIntercept;

#[async_trait]
impl Intercept for MockIntercept {
    async fn before(
        &self,
        task_id: i64,
        _rb: &dyn Executor,
        sql: &mut String,
        _args: &mut Vec<Value>,
        _result: ResultType<&mut Result<ExecResult, rbatis::Error>, &mut Result<Vec<Value>, rbatis::Error>>,
    ) -> Result<Option<bool>, rbatis::Error> {
        *sql = sql.replace("<my_table_name>", &format!("activity_{}",task_id % 2));
        println!("MockIntercept: SQL = {}", sql);
        Ok(Some(true))
    }
}

#[tokio::main]
pub async fn main() -> Result<(), rbatis::Error> {
    _ = fast_log::init(fast_log::Config::new().console());
    let rb = RBatis::new();
    rb.init(rbdc_sqlite::driver::SqliteDriver {}, "sqlite://target/sqlite.db")?;
    // create table
    _=rb.exec("CREATE TABLE activity_0 ( id INTEGER PRIMARY KEY);", vec![]).await;
    _=rb.exec("CREATE TABLE activity_1 ( id INTEGER PRIMARY KEY);", vec![]).await;
    
    let len = rb.intercepts.len();
    println!("len={}", len);
    
    // Create new intercept list and add our mock intercept
    let new_intercept = Arc::new(SyncVec::new());
    let intercept: Arc<dyn Intercept> = Arc::new(MockIntercept {});
    new_intercept.push(intercept);
    
    // Create connection and replace its intercepts
    let mut conn = rb.acquire().await?;
    conn.intercepts = new_intercept;
    println!("conn.intercepts.len={}", conn.intercepts.len());
    
    // Execute query to see the mock intercept in action
    let _ = conn.query("SELECT <my_table_name>", vec![]).await;
    let data = Activity::select_all(&conn).await?;
    println!("data={:?}", json!(data));
    Ok(())
}

/// table
#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub struct Activity {
    pub id: Option<String>,
    pub name: Option<String>,
    pub pc_link: Option<String>,
    pub h5_link: Option<String>,
    pub pc_banner_img: Option<String>,
    pub h5_banner_img: Option<String>,
    pub sort: Option<String>,
    pub status: Option<i32>,
    pub remark: Option<String>,
    pub create_time: Option<DateTime>,
    pub version: Option<i64>,
    pub delete_flag: Option<i32>,
}

//crud!(Activity {},"activity");
crud!(Activity {},"<my_table_name>");

v4.6.12

12 Oct 14:22

Choose a tag to compare

what changes?

 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
struct MockTable {
        pub id: Option<String>,
        pub name: Option<String>,
        pub status: Option<i32>
}
crud!(MockTable{});
let r = MockTable::update_by_map(rb, &table, value!{"id":"1", "column": ["name", "status"]}).await;
  • impl crud! for select target columns
 #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
struct MockTable {
        pub id: Option<String>,
        pub name: Option<String>,
        pub status: Option<i32>
}
crud!(MockTable{});
let tables = MockTable::select_by_map(rb,value!{"id":"1", "column": ["id", "name"]}).await?; 

v4.6.9

11 Oct 17:47

Choose a tag to compare

  • this is an doc fix version
  • merge #586

v4.6.8

02 Jul 10:43

Choose a tag to compare

add page method:

/// create Vec<PageRequest> from (total: u64, page_size: u64)
    pub fn make_page_requests(total: u64, page_size: u64) -> Vec<PageRequest> {
        let mut result = vec![];
        let pages = PageRequest::new(1, page_size).set_total(total).pages();
        for idx in 0..pages {
            let current_page = PageRequest::new(idx + 1, page_size).set_total(total);
            result.push(current_page);
        }
        result
    }

v4.6.7

01 Jun 15:12

Choose a tag to compare

  • fix PageIntercept remove order by sql when run count sql

v4.6.5

31 May 07:19

Choose a tag to compare

  • crud macro *_by_map method will be skip null for example value!{ "name": null }

v4.6.4

29 May 07:49

Choose a tag to compare

  • page intercept will be remove order by when run count sql

v4.6.3

27 May 15:37

Choose a tag to compare

  • in () sql will be return default result

v4.6.2

25 May 13:05

Choose a tag to compare

  • fix crud macro select_by_map(&rb, value!{"id": &[]}).await; if is select empty array ,will be return empty vec result.

v4.6.1

23 May 10:23

Choose a tag to compare

  • fix check empty arg