rbatis html query lang codegen
from html logic just like:
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "https://raw.githubusercontent.com/rbatis/rbatis/master/rbatis-codegen/mybatis-3-mapper.dtd">
<mapper>
<select id="select_by_condition">
`select * from biz_activity`
<where>
<if test="name != ''">
` and name like #{name}`
</if>
<if test="dt >= '2009-12-12 00:00:00'">
` and create_time < #{dt}`
</if>
<choose>
<when test="true">
` and id != '-1'`
</when>
<otherwise>and id != -2</otherwise>
</choose>
` and `
<trim prefixOverrides=" and">
` and name != '' `
</trim>
</where>
</select>
</mapper>
source code for example: ```rust use rbatis::executor::Executor; use rbatis::rbdc::datetime::FastDateTime; use rbatis::sql::page::{Page, PageRequest};
pub struct BizActivity {
pub id: Option
async fn selectbycondition(rb: &mut dyn Executor, page_req: &PageRequest, name: &str, dt: &FastDateTime) -> Vec
log
2022-08-17 17:16:23.624803 INFO rbatis::plugin::log - [rbatis] [402390551883812864] Fetch ==> 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")]
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
)
```rust
"#)]
async fn selectbycondition(
rb: &mut dyn Executor,
name: &str,
a: bool,
) -> rbatis::Result
rust
// pub trait Executor{ //this is rbatis's Executor
// fn exec(&mut self, sql: &str, args: Vec<Value>) -> BoxFuture<'_, Result<ExecResult, Error>>;
// fn fetch(&mut self, sql: &str, args: Vec<Value>) -> BoxFuture<'_, Result<Value, Error>>;
// }
async fn select_by_condition(
rb: &mut dyn rbatis::executor::Executor,
name: &str,
a: bool,
) -> rbatis::Result<Vec<BizActivity>> {
//here is Code generated by rbatis-macro-driver/rbatis-codegen
let mut map = rbs::ValueMap::new();
let mut args = vec![];
map.insert("name",rbs::Value::String(name.to_string()));
let mut sql = "select * from biz_activity where ".to_string();
if map["name"]!=rbs::Value::Null{
sql.push_str(" and name like #{name}");
sql=sql.replace("#{name}", "?");
args.push(map["name"].clone());
}
return rb.fetch(&sql,args).await;
}