1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use rdbc;
use mysql as my;

use std::rc::Rc;
use std::cell::RefCell;

struct MySQLDriver {}

impl MySQLDriver {

    pub fn new() -> Self {
        MySQLDriver {}
    }

    pub fn connect(&self, url: &str) -> rdbc::Result<Rc<dyn rdbc::Connection>> {
        let pool = my::Pool::new(url).unwrap();
        Ok(Rc::new(MySQLConnection { pool }))
    }

}

struct MySQLConnection {
    pool: my::Pool
}


impl rdbc::Connection for MySQLConnection {
    fn create_statement(&self, sql: &str) -> rdbc::Result<Rc<dyn rdbc::Statement>> {
        unimplemented!()
    }
}

struct MySQLStatement {}

impl rdbc::Statement for MySQLStatement {
    fn execute_query(&self) -> rdbc::Result<Rc<RefCell<dyn rdbc::ResultSet>>> {
        unimplemented!()
    }

    fn execute_update(&self) -> rdbc::Result<usize> {
        unimplemented!()
    }
}

struct MySQLResultSet {}

impl rdbc::ResultSet for MySQLResultSet {
    fn next(&mut self) -> bool {
        unimplemented!()
    }

    fn get_i32(&self, i: usize) -> i32 {
        unimplemented!()
    }

    fn get_string(&self, i: usize) -> String {
        unimplemented!()
    }
}


//


#[cfg(test)]
mod tests {

    use super::*;
    use rdbc::{Connection, Statement, ResultSet};

//    #[test]
    fn it_works() {
        let driver = MySQLDriver::new();
        let conn = driver.connect("mysql://root:password@localhost:3307/mysql").unwrap();
        let stmt = conn.create_statement("SELECT foo FROM bar").unwrap();
        let rs = stmt.execute_query().unwrap();
        let mut rs = rs.borrow_mut();
        while rs.next() {
            println!("{}", rs.get_string(1))
        }
    }
}