X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=backend%2Fsrc%2Fdb.rs;h=f3356d206eb8330027e7d8ab6271f370a3e7b52c;hp=0002b41ecb7fd5167e3fef305cf4b604a1d92dd9;hb=87bc628b563f61185c4f9ec48627029b17d32bba;hpb=c012be04a9185ab5924cb314e0378c0cf6655b26 diff --git a/backend/src/db.rs b/backend/src/db.rs index 0002b41..f3356d2 100644 --- a/backend/src/db.rs +++ b/backend/src/db.rs @@ -1,6 +1,39 @@ +use std::path::Path; +use std::fs; +//use rusqlite::types::ToSql; +//use rusqlite::{Connection, Result, NO_PARAMS}; +const CURRENT_DB_VERSION: u32 = 1; -fn create_or_update() { +struct Connection { + pub sqlite_con : rusqlite::Connection +} +impl Connection { + fn new() -> Connection { + + // TODO: use a constant in consts module. + let data_dir = Path::new("data"); + + if !data_dir.exists() { + fs::DirBuilder::new().create(data_dir).unwrap(); + } + + Connection { sqlite_con : rusqlite::Connection::open(data_dir.join("recipes.sqlite")).unwrap() } + } +} + +pub fn create_or_update() { + let connection = Connection::new(); + + // let mut stmt = connection.sqlite_con.prepare("SELECT * FROM versions ORDER BY date").unwrap(); + + //let mut stmt = connection.sqlite_con..prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'").unwrap(); + connection.sqlite_con.query_row( + "SELECT name FROM sqlite_master WHERE type='table' AND name='versions'", + rusqlite::NO_PARAMS, + |row| Ok(dbg!("test")) + ) + .unwrap(); } \ No newline at end of file