Crates.io | sqlrender |
lib.rs | sqlrender |
version | 0.1.0 |
source | src |
created_at | 2023-10-18 16:06:07.478716 |
updated_at | 2023-10-18 16:06:07.478716 |
description | An easy sql generator. |
homepage | |
repository | https://github.com/jdomzhang/sqlrender |
max_upload_size | |
id | 1006924 |
size | 4,889 |
An easy sql generator.
struct
INSERT
/SELECT
/UPDATE
/DELETE
/Soft DELETE
/DDL
sql statementsuse sqlrender::SqlRender;
#[derive(SqlRender, Default)]
struct Person {
id: Option<u64>,
name: Option<String>,
age: Option<u32>,
awesomeness: Option<f64>,
#[sqlrender(skip)]
skipped: Option<bool>,
deleted_at: Option<String>,
}
fn main() {
let mut person = Person {
id: None,
name: Some("Bob".to_string()),
age: Some(24),
awesomeness: Some(0.5),
skipped: Some(true),
..Person::default()
};
{
let sql = person.select_sql().unwrap();
println!("select sql: {}", sql);
let sql = person.scoped_select_sql().unwrap();
println!("scoped select sql: {}", sql);
}
{
let sql = person.insert_sql().unwrap();
println!("insert sql: {}", sql);
}
{
person.id = Some(1);
let sql = person.update_sql().unwrap();
println!("update sql: {}", sql);
}
{
let sql = person.delete_sql().unwrap();
println!("delete sql: {}", sql);
let sql = person.soft_delete_sql().unwrap();
println!("soft delete sql: {}", sql);
}
{
let str = person.table_name();
println!("table name: {}", str);
}
}
Changed the code based on turbosql