X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=backend%2Fsrc%2Fdb.rs;h=6458c7eb7308d384a695f7af38893d0c0e2fb821;hb=HEAD;hp=a2066b81bc225fdf042cb0f7bcd44ac7c4211dc3;hpb=3ebbe8172b0430bae5c554925a4582c9fec545f3;p=recipes.git diff --git a/backend/src/db.rs b/backend/src/db.rs deleted file mode 100644 index a2066b8..0000000 --- a/backend/src/db.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::path::Path; -use std::fs; - -//use rusqlite::types::ToSql; -//use rusqlite::{Connection, Result, NO_PARAMS}; - -const CURRENT_DB_VERSION: u32 = 1; - -pub struct Connection { - con: rusqlite::Connection -} - -impl Connection { - pub 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 { con: rusqlite::Connection::open(data_dir.join("recipes.sqlite")).unwrap() } - } - - pub fn create_or_update(self: &Self) -> rusqlite::Result<&str> { - //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(); - - // Check the Database version. - let version = { - let stmt_version_table = self.con.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'")?; - /*if stmt_version_table.query(rusqlite::NO_PARAMS)?.count() == 0 { - 0 - } else { - 1 // let stmt_versions = self.con.prepare("SELECT number FROM [") - }*/ - 0 - }; - - self.con.query_row( - "SELECT name FROM sqlite_master WHERE type='table' AND name='versions'", - rusqlite::NO_PARAMS, - |row| Ok(dbg!("test")) - ) - } - - pub fn get_all_recipes() { - - } -} \ No newline at end of file