use std::time::SystemTime; use db_derive::{PostgresMeta}; mod test; #[allow(dead_code)] #[derive(Debug, PostgresMeta)] #[pg_mapper(table = "oms_order")] pub struct Command{ #[id] id: i64, #[field(type="varchar", length=50)] name: String, #[field(type="varchar", length=200)] nickname: Option, age: Option, create_time: Option, } #[derive(Debug)] enum Data { BigInt(Option), Int(Option), SmallInt(Option), Float(Option), String(Option), SystemTime(Option), } impl Command { pub fn to_vec_1(self) -> Result, &'static str> { let mut v = vec![]; v.push(Data::BigInt(Some(self.id))); v.push(Data::String(Some(self.name))); v.push(Data::String(self.nickname)); v.push(Data::SmallInt(self.age)); v.push(Data::SystemTime(self.create_time)); Ok(v) } } pub fn main(){ let mut data_vec: Vec = Vec::new(); data_vec.push(Data::Int(Some(10))); data_vec.push(Data::Float(Some(3.14))); data_vec.push(Data::String(Some(String::from("Hello, World!")))); for datum in data_vec { match datum { Data::Int(i) => println!("Integer: {}", i.unwrap()), Data::Float(f) => println!("Float: {}", f.unwrap()), Data::String(s) => println!("String: {}", s.unwrap()), _ => {} } } let c = Command::meta(); let (table_name, fields): (String, Vec<(String, String, u16, String, bool)>) = Command::meta(); println!("{:?}", fields); let b = Command { id: 0, name: "111".to_string(), nickname: None, age: None, create_time: None, }; let b = b.to_vec_1(); println!("builder: {:?}", b); // let create = Command::sql().create(); // println!("create: {:?}", create); // // let insert = Command::sql().insert(); // println!("insert: {:?}", insert); // // let select = Command::sql() // .condition(Some("uid=$1".to_string())) // .order(Some("createdate desc".to_string())) // .select(); // println!("select: {:?}", select); // // let update = Command::sql() // .renew(Some("uid=$1".to_owned())) // .condition(Some("uid=$2".to_string())) // .update(); // println!("update: {:?}", update); // // let delete = Command::sql().delete(); // println!("delete: {:?}", delete); }