v1.8.74
- rbatis log plugin will be print error log
- py_sql and sql macro allow Load SQL files dynamically(In debug mode, rewrite the SQL to avoid duplicate compilation)see example/py_sql_test.rs
first , define py_sql.sql
select * from biz_activity where delete_flag = 0
if name != '':
and name=#{name}
then,load file
///load from file
fn load_file_str(file_name:&str)->String{
let mut f =File::open(file_name).unwrap();
let mut s=String::new();
f.read_to_string(&mut s);
return s;
}
///load file py_sql(Each read file changes every time)
#[py_sql(rb, load_file_str("py_sql.sql"))]
async fn py_select_file(rb: &Rbatis, page_req: &PageRequest, name: &str) -> Page<BizActivity> {}
lazy_static!(
pub static ref PY_SQL_FILE_STR:String=load_file_str("py_sql.sql");
);
///load file py_sql(only load file once)
#[py_sql(rb, PY_SQL_FILE_STR)]
async fn py_select_file_static(rb: &Rbatis, page_req: &PageRequest, name: &str) -> Page<BizActivity> {}
/// test load py_sql from file
#[async_std::test]
pub async fn test_py_select_file() {
fast_log::init_log("requests.log", 1000, log::Level::Info, None, true);
//use static ref
let rb = Rbatis::new();
rb.link("mysql://root:123456@localhost:3306/test")
.await
.unwrap();
let mut result = py_select_file(&rb, &PageRequest::new(1, 10), "test")
.await
.unwrap();
println!("{:?}", result);
result = py_select_file_static(&rb, &PageRequest::new(1, 10), "test")
.await
.unwrap();
println!("{:?}", result);
}