Rust Compile Time ORM robustness,async, pure Rust Dynamic SQL
APACHE-2.0 License
Bot releases are visible (Hide)
Published by zhuxiujia about 1 year ago
v4.4.3
crud! macro
search_total,when search_total=true exec count sql.crud! macro
change update_by_column_batch implPublished by zhuxiujia about 1 year ago
v4.4.2
delete_by_column_batch
update_by_column_batch
Published by zhuxiujia about 1 year ago
v4.4.1
Intercept
use #[async_trait]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
Published by zhuxiujia about 1 year ago
v4.3.15
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)
}
}
Published by zhuxiujia about 1 year ago
v4.3.14
_result: ResultType<&mut Option<ExecResult>, &mut Option<Vec<Value>>>
Support early returnPublished by zhuxiujia about 1 year ago
v4.3.13
impl_select_page
of limit sql's bugPublished by zhuxiujia about 1 year ago
v4.3.12
Published by zhuxiujia about 1 year ago
v4.3.11
impl_select_page!
and htmlsql_select_page!
decode empty count
value fail on postgresJsonV
maybe decode failPublished by zhuxiujia over 1 year ago
v4.3.10
Published by zhuxiujia over 1 year ago
v4.3.9
impl_select_page!
Generate and reuse only one functionPublished by zhuxiujia over 1 year ago
v4.3.8
impl_select_page!
macro ${limit_sql}
maybe doesn't workPublished by zhuxiujia over 1 year ago
v4.3.7
Published by zhuxiujia over 1 year ago
v4.3.6
sql_intercepts
to intercepts
Published by zhuxiujia over 1 year ago
v4.3.5
before
and after
methodimpl 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(())
}
}
RBatis
struct is very cleanpub 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>>>,
}
Published by zhuxiujia over 1 year ago
v4.3.4
Published by zhuxiujia over 1 year ago
v4.3.3
Published by zhuxiujia over 1 year ago
v4.3.0
Published by zhuxiujia over 1 year ago
v4.2.3
#[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!()
}
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" |
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" |
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 stringrbdc::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"}
let v = rbs::to_value! {};
let m = rbs::to_value! {
1: 1,
"2": 2,
};
assert_eq!(r#"{1:1,"2":2}"#, m.to_string());