diff --git a/foods.db b/foods.db index a769939..c8e49e5 100644 Binary files a/foods.db and b/foods.db differ diff --git a/src/create_tables.sql b/src/create_tables.sql index f244c7f..4b971b1 100644 --- a/src/create_tables.sql +++ b/src/create_tables.sql @@ -6,4 +6,4 @@ CREATE TABLE IF NOT EXISTS food ( target_servings INTEGER NOT NULL DEFAULT 1, actual_servings INTEGER NOT NULL DEFAULT 0, color TEXT NOT NULL DEFAULT 'white' -); +) STRICT; diff --git a/src/main.rs b/src/main.rs index 56f3ad2..d1d1eb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,7 +81,6 @@ struct PreparedStatements {} impl<'conn> PreparedStatements { fn check(conn: &Connection) -> rusqlite::Result { - conn.prepare_cached(include_str!("create_tables.sql"))?; conn.prepare_cached(include_str!("increase.sql"))?; conn.prepare_cached(include_str!("decrease.sql"))?; conn.prepare_cached(include_str!("get_food.sql"))?; @@ -91,11 +90,6 @@ impl<'conn> PreparedStatements { Ok(PreparedStatements {}) } - fn create_tables(conn: &'conn Connection) -> CachedStatement<'conn> { - conn.prepare_cached(include_str!("create_tables.sql")) - .expect("cached statement is invalid") - } - fn increase(conn: &'conn Connection) -> CachedStatement<'conn> { conn.prepare_cached(include_str!("increase.sql")) .expect("cached statement is invalid") @@ -149,12 +143,14 @@ async fn main() -> Result<(), std::io::Error> { let db_connecion_str = "./foods.db".to_string(); debug!(db_connecion_str, "opening database"); let conn = Connection::open(db_connecion_str).expect("failed to open database"); - PreparedStatements::check(&conn).expect("failed to prepare sql statements"); - if let Err(e) = PreparedStatements::create_tables(&conn).execute(()) { + + if let Err(e) = conn.execute(include_str!("create_tables.sql"), ()) { error!(?e, "failed to create tables"); panic!("failed to create tables: {:#?}", e); } + PreparedStatements::check(&conn).expect("failed to prepare sql statements"); + let app = Router::new() .route("/", get(root)) .route("/increase/{id}", post(increase))