generate_sql

快速生成sql语句(根据传入struct,自动生成sql语句)

引入

generate_sql = "0.1.2"

编写struct,添加GenSql

```

[derive(Debug,GenSql)]

struct SqlGen{ id:String, nickname:Option, age:i32, height:Option, createtime:Option } ```

使用方法 (这里时间目前只支持chrono::NaiveDate)

``` fn main() { let model = SqlGen{ id:"id".tostring(), nickname:Some("昵称".tostring()), age:18, height:Some(15.6), createtime:Some(chrono::NaiveDate::fromymd(2016, 7, 8).and_hms(9, 10, 11)) };

let insert_sql = SqlGen::insert_sql(&_model,"sys_user".to_string());
let update_sql = SqlGen::update_sql(&_model, "sys_user".to_string(), "id".to_string());
let select_sql = SqlGen::select_sql(&_model,"sys_user".to_string());
let delete_sql = SqlGen::delete_sql(&_model, "sys_user".to_string(), "id".to_string());
println!("{}",insert_sql);
println!("{}",update_sql);
println!("{}",select_sql);
println!("{}",delete_sql);

} ```

输出结果

insert into sys_user (nick_name,age,id,height,create_time) values ('昵称',18,'777777',15.6,'2016-07-08 09:10:11') update sys_user set nick_name='昵称',age=18,height=15.6,create_time='2016-07-08 09:10:11' where id='777777' select * from sys_user where nick_name='昵称' and age=18 and id='777777' and height=15.6 and create_time='2016-07-08 09:10:11' delete from sys_user where id='777777'