+use std::path::Path;\r
+use std::fs;\r
\r
+//use rusqlite::types::ToSql;\r
+//use rusqlite::{Connection, Result, NO_PARAMS};\r
\r
+const CURRENT_DB_VERSION: u32 = 1;\r
\r
-fn create_or_update() {\r
+struct Connection {\r
+ pub sqlite_con : rusqlite::Connection\r
+}\r
\r
+impl Connection {\r
+ fn new() -> Connection {\r
+\r
+ // TODO: use a constant in consts module.\r
+ let data_dir = Path::new("data");\r
+\r
+ if !data_dir.exists() {\r
+ fs::DirBuilder::new().create(data_dir).unwrap();\r
+ }\r
+\r
+ Connection { sqlite_con : rusqlite::Connection::open(data_dir.join("recipes.sqlite")).unwrap() }\r
+ }\r
+}\r
+\r
+pub fn create_or_update() {\r
+ let connection = Connection::new();\r
+\r
+ // let mut stmt = connection.sqlite_con.prepare("SELECT * FROM versions ORDER BY date").unwrap();\r
+\r
+ //let mut stmt = connection.sqlite_con..prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='versions'").unwrap();\r
+ connection.sqlite_con.query_row(\r
+ "SELECT name FROM sqlite_master WHERE type='table' AND name='versions'",\r
+ rusqlite::NO_PARAMS,\r
+ |row| Ok(dbg!("test"))\r
+ )\r
+ .unwrap();\r
}
\ No newline at end of file
use itertools::Itertools;
mod consts;
+mod db;
#[derive(Template)]
#[template(path = "main.html")]
println!("Configuration: {:?}", config);
+ let database_connection = db::create_or_update();
+
let mut listenfd = ListenFd::from_env();
let mut server =
HttpServer::new(
fn process_args() -> bool {
fn print_usage() {
println!("Usage:");
- println!(" {} [--help]", get_exe_name());
+ println!(" {} [--help] [--test]", get_exe_name());
}
let args: Vec<String> = args().collect();
if args.iter().any(|arg| arg == "--help") {
print_usage();
return true
+ } else if args.iter().any(|arg| arg == "--test") {
+ let database_connection = db::create_or_update();
+ return true
}
false