rbatis html query lang codegen
from html logic just like:
`select * from biz_activity`
` and name like #{name}`
` and create_time < #{dt}`
` and id != '-1'`
and id != -2
` and `
` and name != '' `
source code for example:
use Executor;
use DateTime;
use ;
async
2022-08-17 17:16:23.624803 INFO rbatis::plugin::log - [rbatis] [402390551883812864] query ==> select * from biz_activity where name like ? and create_time < ? and id != '-1' and name != ''
[rbatis] Args ==> ["test",DateTime("2022-08-17 17:16:23")]
How it works
1. Whenever user define html_sql
method(Of course, py_sql
The implementation is also based on the py_sql
syntax tree escaped to html_sql
)
async
2. RBatis expr
- RBatis expr is
#{name}
,#{age + 1}
,${age + 1}
and code test:<if test="dt >= '2009-12-12 00:00:00'"></if>
- RBatis expr will be Convert to original rust code,if RBatis expression =
#{age + 1}
,the code =rb_arg_map["age"].op_add(1)
- RBatis expr directly use strings to compare and process date types,just like
<if test="dt >= '2009-12-12 00:00:00'"></if>
,#{dt >= '2009-12-12 00:00:00'}
3. The function body is generated through the process macro via rbatis-codegen
// pub trait Executor{ //this is rbatis's Executor
// fn exec(&mut self, sql: &str, args: Vec<Value>) -> BoxFuture<'_, Result<ExecResult, Error>>;
// fn query(&mut self, sql: &str, args: Vec<Value>) -> BoxFuture<'_, Result<Value, Error>>;
// }
pub async