2020-05-20 17:05:59 +00:00
|
|
|
use comunic_server::data::config::{conf, Config};
|
2020-05-21 07:21:58 +00:00
|
|
|
use comunic_server::helpers::database;
|
2020-05-21 07:38:41 +00:00
|
|
|
use mysql::prelude::Queryable;
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
struct User {
|
|
|
|
id : i32,
|
|
|
|
name : String,
|
|
|
|
email: String,
|
|
|
|
age: i32
|
|
|
|
}
|
2020-05-20 17:05:59 +00:00
|
|
|
|
2020-05-20 15:46:05 +00:00
|
|
|
fn main() {
|
2020-05-20 17:05:59 +00:00
|
|
|
|
|
|
|
// Load configuration
|
|
|
|
Config::load("config.yaml").expect("Could not load configuration!");
|
|
|
|
|
2020-05-21 07:21:58 +00:00
|
|
|
// Connect to the database
|
|
|
|
database::connect(&conf().database).expect("Could not connect to database!");
|
2020-05-20 17:05:59 +00:00
|
|
|
|
2020-05-21 07:38:41 +00:00
|
|
|
let mut conn = database::get_connection().unwrap();
|
|
|
|
let res = conn.query_map("SELECT id, name, email, age FROM user", |(id, name, email, age)| {
|
|
|
|
User {id, name, email, age}
|
|
|
|
}).unwrap();
|
|
|
|
println!("{:#?}", res);
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-05-20 15:46:05 +00:00
|
|
|
println!("Hello, world!");
|
|
|
|
}
|