about summary refs log blame commit diff stats
path: root/themes/snikket
blob: ac5290bb6670f2b891fad83cda297be6f5f28942 (plain) (tree)

















































































                                  
[colours]
bkgnd=orange1
cmd.wins.unread=yellow
titlebar=darkblue
titlebar.text=orange1
titlebar.brackets=orange3
titlebar.unencrypted=orange3
titlebar.encrypted=orange1
titlebar.untrusted=red
titlebar.trusted=orange1
titlebar.online=orange1
titlebar.offline=white
titlebar.away=wheat4
titlebar.chat=yellow
titlebar.dnd=red
titlebar.xa=darkorange3
statusbar=darkblue
statusbar.text=orange1
statusbar.brackets=default
statusbar.active=default
statusbar.new=yellow
statusbar.current=orange1
statusbar.time=orange3
main.text=darkblue
main.text.me=blue
main.text.them=blue3
main.splash=darkblue
main.help.header=blue1
main.text.history=darkblue
main.time=navyblue
input.text=darkblue
subscribed=darkblue
unsubscribed=blue3
otr.started.trusted=green
otr.started.untrusted=yellow
otr.ended=red
otr.trusted=green
otr.untrusted=yellow
online=blue3
away=wheat4
chat=blue3
dnd=red
xa=darkorange3
offline=yellow
incoming=yellow
mention=yellow
trigger=yellow
typing=yellow
gone=orange4
error=red
roominfo=blue1
roommention=blue1
roommention.term=blue
roomtrigger=blue1
roomtrigger.term=blue
me=blue1
them=blue3
roster.header=blue1
roster.chat=blue3
roster.online=blue3
roster.away=wheat4
roster.xa=darkorange3
roster.dnd=red
roster.offline=deepskyblue4
roster.chat.active=blue3
roster.online.active=blue3
roster.away.active=wheat4
roster.xa.active=darkorange3
roster.dnd.active=yellow
roster.offline.active=default
roster.chat.unread=blue3
roster.online.unread=blue3
roster.away.unread=wheat4
roster.xa.unread=darkorange3
roster.dnd.unread=red
roster.offline.unread=deepskyblue4
roster.room=blue3
roster.room.unread=darkblue
roster.room.mention=deepskyblue3
roster.room.trigger=blue1
occupants.header=blue1
receipt.sent=blue3
:50:51 -0400 fleshing out types' href='/gbmor/clinte/commit/src/db.rs?h=v2.1.0&id=9ee17f15bb380d31d55d83586ebdf3644cf326af'>9ee17f1 ^
07511f9 ^












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
              
             
              
 

                                       

                 



                       

 
                
                 
                                   

 

                                       

                                         
                                                         
                    







                                                              
                                                          







                                           




                                                      


            

                                   

     












                                                                    
use log::info;
use rusqlite;
use std::time;

const DB_PATH: &str = "/tmp/clinte.db";

#[derive(Debug)]
pub struct Post {
    pub id: u32,
    pub title: String,
    pub author: String,
    pub body: String,
}

#[derive(Debug)]
pub struct Conn {
    pub conn: rusqlite::Connection,
}

impl Conn {
    fn init() -> rusqlite::Connection {
        let start = time::Instant::now();
        info!("Connecting to database");
        let conn = rusqlite::Connection::open_with_flags(
            DB_PATH,
            rusqlite::OpenFlags::SQLITE_OPEN_FULL_MUTEX
                | rusqlite::OpenFlags::SQLITE_OPEN_CREATE
                | rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE,
        )
        .expect("Could not connect to DB");

        conn.execute(
            "CREATE TABLE IF NOT EXISTS posts (
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
            title TEXT NOT NULL,
            author TEXT NOT NULL,
            body TEXT NOT NULL
        )",
            rusqlite::NO_PARAMS,
        )
        .expect("Could not initialize DB");

        info!(
            "Database connection established in {}ms",
            start.elapsed().as_millis()
        );

        conn
    }

    pub fn new() -> Self {
        Conn { conn: Conn::init() }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_new() {
        let conn = Conn::init();
        let mut stmt = conn.prepare("SELECT * FROM POSTS").unwrap();

        stmt.query_map(rusqlite::NO_PARAMS, |row| Ok(()));
    }
}