Update dependencies
[recipes.git] / backend / src / db.rs
1 use std::path::Path;
2 use std::fs;
3
4 //use rusqlite::types::ToSql;
5 //use rusqlite::{Connection, Result, NO_PARAMS};
6
7 const CURRENT_DB_VERSION: u32 = 1;
8
9 struct Connection {
10 pub sqlite_con : rusqlite::Connection
11 }
12
13 impl Connection {
14 fn new() -> Connection {
15
16 // TODO: use a constant in consts module.
17 let data_dir = Path::new("data");
18
19 if !data_dir.exists() {
20 fs::DirBuilder::new().create(data_dir).unwrap();
21 }
22
23 Connection { sqlite_con : rusqlite::Connection::open(data_dir.join("recipes.sqlite")).unwrap() }
24 }
25 }
26
27 pub fn create_or_update() {
28 let connection = Connection::new();
29
30 // let mut stmt = connection.sqlite_con.prepare("SELECT * FROM versions ORDER BY date").unwrap();
31
32 //let mut stmt = connection.sqlite_con..prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'").unwrap();
33 connection.sqlite_con.query_row(
34 "SELECT name FROM sqlite_master WHERE type='table' AND name='versions'",
35 rusqlite::NO_PARAMS,
36 |row| Ok(dbg!("test"))
37 )
38 .unwrap();
39 }