rbatis

Rust Compile Time ORM robustness,async, pure Rust Dynamic SQL

APACHE-2.0 License

Downloads
1.1M
Stars
2.3K
Committers
25

Bot releases are hidden (Show)

rbatis - v4.4.3

Published by zhuxiujia about 1 year ago

v4.4.3

  • fix crud! macro search_total,when search_total=true exec count sql.
  • crud! macro change update_by_column_batch impl
rbatis - v4.4.2

Published by zhuxiujia about 1 year ago

v4.4.2

  • crud macro add delete_by_column_batch
  • (unstable)crud macro add update_by_column_batch
rbatis - v4.4.1

Published by zhuxiujia about 1 year ago

v4.4.1

  • update Intercept use #[async_trait]
  • Interceptors support modifying SQL statements, parameters, returning early, and executing the next interceptor,Here is an interceptor that supports modifying the PG database for sql returning id see
  • crud! macro don't need &mut ,Very simple use &rb, &tx see https://github.com/rbatis/example/blob/main/src/crud.rs
rbatis - v4.3.15

Published by zhuxiujia about 1 year ago

v4.3.15

  • The previous interceptor can decide whether to allow the next interceptor to continue execution
  • change Intercept to
pub trait Intercept: Send + Sync + Debug {
    fn name(&self) -> &str {
        std::any::type_name::<Self>()
    }

    /// 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
    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<bool, Error> {
        Ok(true)
    }

    /// 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
    fn after(
        &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<bool, Error> {
        Ok(true)
    }
}
rbatis - v4.3.14

Published by zhuxiujia about 1 year ago

v4.3.14

  • Intercept plugin trait add method param _result: ResultType<&mut Option<ExecResult>, &mut Option<Vec<Value>>> Support early return
rbatis - v4.3.13

Published by zhuxiujia about 1 year ago

v4.3.13

  • fix macro impl_select_page of limit sql's bug
rbatis - v4.3.12

Published by zhuxiujia about 1 year ago

v4.3.12

  • fix #433
  • remove some unused code
rbatis - v4.3.11

Published by zhuxiujia about 1 year ago

v4.3.11

  • fix impl_select_page! and htmlsql_select_page! decode empty count value fail on postgres
  • fix rbdc JsonV maybe decode fail
rbatis - v4.3.10

Published by zhuxiujia over 1 year ago

v4.3.10

  • Fixed the handling logic for potential time rollback in the Snowflake algorithm.
rbatis - v4.3.9

Published by zhuxiujia over 1 year ago

v4.3.9

  • impl_select_page! Generate and reuse only one function
rbatis - v4.3.8

Published by zhuxiujia over 1 year ago

v4.3.8

  • fix impl_select_page! macro ${limit_sql} maybe doesn't work
rbatis - v4.3.7

Published by zhuxiujia over 1 year ago

v4.3.7

  • this update For compatibility with older versions
rbatis - v4.3.6

Published by zhuxiujia over 1 year ago

v4.3.6

  • fix about RBatisOption,rename sql_intercepts to intercepts
rbatis - v4.3.5

Published by zhuxiujia over 1 year ago

v4.3.5

  • edit Intercept trait, add before and after method
  • log plugin move to intercepts. move to impl Intercept for LogInterceptor
impl Intercept for LogInterceptor {
    fn before(
        &self,
        task_id: i64,
        _rb: &dyn Executor,
        sql: &mut String,
        args: &mut Vec<Value>,
    ) -> Result<(), Error> {
        if self.get_level_filter() == LevelFilter::Off {
            return Ok(());
        }
        let level = self.to_level().unwrap();
        //send sql/args
        let op;
        if sql.trim_start().starts_with("select") {
            op = "query";
        } else {
            op = "exec ";
        }
        log!(level,"[rbatis] [{}] {} => `{}` {}",task_id,op,&sql,RbsValueDisplay { inner: args });
        Ok(())
    }

    fn after(
        &self,
        task_id: i64,
        _rb: &dyn Executor,
        sql: &mut String,
        _args: &mut Vec<Value>,
        result: Result<ResultType<&mut ExecResult, &mut Vec<Value>>, &mut Error>,
    ) -> Result<(), Error> {
        if self.get_level_filter() == LevelFilter::Off {
            return Ok(());
        }
        let level = self.to_level().unwrap();
        //recv sql/args
        match result {
            Ok(result) => {
                let op;
                if sql.trim_start().starts_with("select") {
                    op = "query";
                } else {
                    op = "exec ";
                }
                match result {
                    ResultType::Exec(result) => {
                        log!(level,"[rbatis] [{}] {}  <= rows_affected={}",task_id, op, result);
                    }
                    ResultType::Query(data) => {
                        if is_debug_mode() {
                            log!(level,"[rbatis] [{}] {} <= len={},rows={}",
                                        task_id,
                                        op,
                                        data.len(),
                                        RbsValueDisplay { inner: data }
                                );
                        } else {
                            log!(level,"[rbatis] [{}] {} <= len={}", task_id, op, data.len());
                        }
                    }
                }
            }
            Err(e) => {
                log!(level,"[rbatis] [{}] exec  <= {}", task_id, e);
            }
        }
        Ok(())
    }
}

  • now RBatis struct is very clean
pub struct RBatis {
    // the connection pool
    pub pool: Arc<OnceLock<Pool>>,
    // intercept vec(default the intercepts[0] is a log interceptor)
    pub intercepts: Arc<SyncVec<Arc<dyn Intercept>>>,
}
  • Speed increases because interceptor logging optimizes the log printing process, speeding up every query and update operation by 200ns-300ns
rbatis - v4.3.4

Published by zhuxiujia over 1 year ago

v4.3.4

  • rename Rbatis to RBatis
rbatis - v4.3.3

Published by zhuxiujia over 1 year ago

v4.3.3

  • support feature tls-rustls/tls-native-tls
rbatis - v4.3.0

Published by zhuxiujia over 1 year ago

v4.3.0

  • reset to 4.0 code
  • keep all dep crates version=4.3
  • keep to_value!() macro support to_value!{ },to_value!{ id:1, }
  • sqlite driver map/array will be insert to json
rbatis - v4.2.3

Published by zhuxiujia over 1 year ago

v4.2.3

  • sql() method impl to trim end_names.
  • for example("2009-12-12 00:00:00DT" -> "2009-12-12 00:00:00" ):
#[html_sql(r#"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "https://raw.githubusercontent.com/rbatis/rbatis/master/rbatis-codegen/mybatis-3-mapper.dtd">
  <select id="select_by_condition">
        `select * from biz_activity`
        <where>
            <if test="dt.sql() >= '2009-12-12 00:00:00'">
                `  create_time < ${dt.sql()}`
            </if>
        </where>
  </select>"#)]
async fn select_by_condition(
    rb: &mut dyn Executor,
    name: &str,
    dt: &DateTime,
    a: bool,
) -> rbatis::Result<Vec<BizActivity>> {
    impled!()
}
rbatis - v4.2.0

Published by zhuxiujia over 1 year ago

v4.2.0

  • rbatis-codegen support allow string type value + - * /

  • rbs Serialize rbdc::types

type value
Date "2022-12-12D"
DateTime "2022-12-12 12:12:12DT"
Decimal "12.12222DEC"
Json {"k":"v"}
Json Array [{"k":"v"}]
Time "12:12:12T"
Timestamp "1679237085TS"
Uuid "1234-1234-1234-1234-1222UUID"
  • other crates Serialize rbdc::types
type value
Date "2022-12-12"
DateTime "2022-12-12 12:12:12"
Decimal "12.12222"
Json {"k":"v"}
Json Array [{"k":"v"}]
Time "12:12:12"
Timestamp "1679237085"
Uuid "1234-1234-1234-1234-1222"
rbatis - v4.1.0

Published by zhuxiujia over 1 year ago

v4.1.0

  • rbs crates removed enum type Ext. This change is mainly for json specification compatibility, so special types such asDateTime will be serialized to map types such as {"type":"DateTime","value":"2023-01-01 00:00:00.000001"}
  • rbs::Value call .to_string() will be return json string
  • rbdc::types change from pub struct Decimal(String) to pub struct Decimal { pub r#type: String, pub value: String, }
  • rbdc::types Display and Format change from Decimal("1.0000") to Display Value "1.0000" . source value is {"type":"Decimal","value":"1.0000"}
  • Macro to_value enhanced to support defining map types. for example:
let v = rbs::to_value! {};
let m = rbs::to_value! {
            1: 1,
            "2": 2,
        };
assert_eq!(r#"{1:1,"2":2}"#, m.to_string());