diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/db.rs b/src/db.rs index 6c1214b..93d73a8 100644 --- a/src/db.rs +++ b/src/db.rs @@ -4,6 +4,8 @@ use rusqlite; use std::sync::mpsc; use std::time; +const DB_PATH: &str = "/tmp/clinte.db"; + #[derive(Debug)] pub struct Post { id: u32, @@ -20,8 +22,8 @@ pub struct Conn { #[derive(Debug)] pub enum Cmd { - Create, - Update, + Create(Post), + Update(Post), Disconnect, NOOP, } @@ -31,7 +33,7 @@ impl Conn { let start = time::Instant::now(); info!("Connecting to database"); let conn = rusqlite::Connection::open_with_flags( - "/tmp/db.sql", + DB_PATH, rusqlite::OpenFlags::SQLITE_OPEN_FULL_MUTEX | rusqlite::OpenFlags::SQLITE_OPEN_CREATE | rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE, @@ -40,7 +42,7 @@ impl Conn { conn.execute( "CREATE TABLE IF NOT EXISTS posts ( - id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + id INTEGER PRIMARY KEY NOT NULL, title TEXT NOT NULL, author TEXT NOT NULL, body TEXT NOT NULL @@ -66,10 +68,10 @@ impl Conn { } impl Cmd { - pub fn new(txt: &str) -> Self { + pub fn new(txt: &str, post: Post) -> Self { match txt { - "create" => Cmd::Create, - "update" => Cmd::Update, + "create" => Cmd::Create(post), + "update" => Cmd::Update(post), "disconnect" => Cmd::Disconnect, _ => Cmd::NOOP, } |