about summary refs log tree commit diff stats
path: root/src/db.rs
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-08-27 23:32:30 -0400
committerBen Morrison <ben@gbmor.dev>2019-08-27 23:32:30 -0400
commit05649a5b2c4a122cfb1644f009825abfc7345d72 (patch)
tree4921b4de4d8cfdce3ebe8eb33b163b40c62dca40 /src/db.rs
parent99273b69b161ae472f5ee37707d0a50ef5608be9 (diff)
downloadclinte-05649a5b2c4a122cfb1644f009825abfc7345d72.tar.gz
finished posting and display
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs36
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()
-    }
 }