#[cfg(test)] mod mysql { use std::{env, fs}; use br_mysql::connect::Connect; use br_mysql::Mysql; fn init() -> Result { env::set_var("RUST_LOG", "INFO"); env_logger::init(); let tt = fs::read_to_string("./config/db.json").unwrap(); let tt = json::parse(&*tt).unwrap(); let mut mysql = match Mysql::new(tt["connects"][tt["default"].as_str().unwrap()].clone()) { Ok(e) => e, Err(e) => return Err(e) }; Ok(mysql.get_conn("").unwrap().clone()) } #[cfg(test)] mod query{ use crate::mysql::init; #[test] fn query_SELECT() { let mut db = init().unwrap(); let res = db.query("SELECT id,api FROM `log_log` as i limit 0,700").unwrap(); println!("{}", res); } #[test] fn query_count() { let mut db = init().unwrap(); let res = db.query("SELECT count(*) FROM `log_log`").unwrap(); println!("{}", res); } #[test] fn query_PROCESSLIST() { let mut db = init().unwrap(); match db.query("SHOW PROCESSLIST") { Ok(e) => { println!("{:#}", e); } Err(e) => { println!("{:?}", e); } } } } #[cfg(test)] mod execute{ use crate::mysql::init; #[test] fn execute_TRANSACTION() { let mut db = init().unwrap(); match db.execute("START TRANSACTION") { Ok(e) => { println!("{:?}", e); } Err(e) => { println!("{:?}", e); } } } } }