Skip to main content

rusqlite_struct/
lib.rs

1pub mod rusqlite_struct;
2pub use rusqlite_struct::RusqliteStruct;
3
4pub mod rusqlite_struct_helper;
5
6struct Test {
7    id: i32,
8    test: String
9}
10
11impl RusqliteStruct for Test {
12    fn struct_name() -> &'static str {
13        "Test"
14    }
15
16    fn field_names() -> &'static [&'static str] {
17        &["id", "test"]
18    }
19}
20
21#[test]
22pub fn test() {
23        let to_execute = format!(
24            "INSERT INTO {} ({}) VALUES ({})",
25            Test::struct_name(),
26            format!("{}", Test::field_names().join(",")),
27            format!("{}", Test::field_names().iter().map(|s| format!(":{}", s)).collect::<Vec<String>>().join(","))
28        );
29
30
31    assert_eq!(to_execute, "INSERT INTO Test (id,test) VALUES (:id,:test)")
32}