Created
March 12, 2015 07:59
-
-
Save arossouw/fb4bc179c5a56302a36b to your computer and use it in GitHub Desktop.
Rust - Beginnings (MySQL Client)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate mysql; | |
extern crate time; | |
use time::Timespec; | |
use std::num::Float; | |
use mysql::conn::{MyOpts}; | |
use mysql::conn::pool::{MyPool}; | |
use mysql::value::{from_value}; | |
use std::default::{Default}; | |
use std::f32; | |
struct payment { | |
customer_id : i32 | |
} | |
fn main() | |
{ | |
let opts = MyOpts{ | |
user: Some("mysqluser".to_string()), | |
pass: Some("mysqluser".to_string()), | |
db_name: Some("dbsales".to_string()), | |
tcp_addr: Some("10.0.0.82".to_string()), | |
..Default::default() | |
}; | |
let pool = MyPool::new(opts).unwrap(); | |
let mut stmt = pool.prepare( | |
"SELECT customer_id | |
FROM | |
payment").unwrap(); | |
for row in stmt.execute(&[]) { | |
let row = row.unwrap(); | |
let c = payment { | |
customer_id : from_value(&row[0]) | |
}; | |
println!("{}" , c.customer_id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment