From b60ac5fb3f86a836e80f0589986aed1adc0c5024 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 2 Oct 2024 17:25:20 +0300 Subject: [PATCH] handle errors, drop version from struct --- src/app/database.rs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/app/database.rs b/src/app/database.rs index d5a0dbd7..66131dd1 100644 --- a/src/app/database.rs +++ b/src/app/database.rs @@ -2,33 +2,26 @@ use std::sync::Arc; pub struct Database { connection: Arc, - // Autostart migrate feature on app and db versions mismatch - version: i32, } impl Database { // Construct new application DB pub fn init(connection: Arc) -> Database { - // Create app table if not exist yet - /* - connection - .execute( - r" - CREATE TABLE IF NOT EXISTS `app` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, - `version` VARCHAR NOT NULL - ) - ", - ) - .unwrap(); // @TODO handle errors */ + // Init app table + if let Err(e) = connection.execute( + r" + CREATE TABLE IF NOT EXISTS `app` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP, + ) + ", + ) { + panic!("{e}"); + } // Return struct - Self { - connection, - version: 1, // @TODO - } + Self { connection } } // Restore previous browser session from DB