diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/src/db.rs b/src/db.rs index 93d73a8..a0cc2cf 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,23 +1,20 @@ use log::info; -use rand; use rusqlite; -use std::sync::mpsc; use std::time; const DB_PATH: &str = "/tmp/clinte.db"; #[derive(Debug)] pub struct Post { - id: u32, - title: String, - author: String, - body: String, + pub id: u32, + pub title: String, + pub author: String, + pub body: String, } #[derive(Debug)] pub struct Conn { - db: rusqlite::Connection, - rx: mpsc::Receiver<Cmd>, + pub conn: rusqlite::Connection, } #[derive(Debug)] @@ -42,7 +39,7 @@ impl Conn { conn.execute( "CREATE TABLE IF NOT EXISTS posts ( - id INTEGER PRIMARY KEY NOT NULL, + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title TEXT NOT NULL, author TEXT NOT NULL, body TEXT NOT NULL @@ -59,11 +56,8 @@ impl Conn { conn } - pub fn new(rx: mpsc::Receiver<Cmd>) -> Self { - Conn { - db: Conn::init(), - rx, - } + pub fn new() -> Self { + Conn { conn: Conn::init() } } } @@ -80,7 +74,7 @@ impl Cmd { impl Post { pub fn new(title: &str, author: &str, body: &str) -> Self { - let id = rand::random::<u32>(); + let id = 0; let title = title.to_string(); let author = author.to_string(); let body = body.to_string(); @@ -91,16 +85,4 @@ impl Post { body, } } - pub fn id(&self) -> String { - format!("{}", self.id) - } - pub fn title(&self) -> String { - self.title.clone() - } - pub fn author(&self) -> String { - self.author.clone() - } - pub fn body(&self) -> String { - self.body.clone() - } } |