diff --git a/src/database.rs b/src/database.rs index e5ff76e..a046b59 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,46 +1,7 @@ use log::debug; -use sqlx::{migrate::MigrateDatabase, Connection, Sqlite, SqliteConnection, SqlitePool}; +use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool}; -#[derive(sqlx::FromRow, Debug)] -pub struct Sheet { - name: String, - // #[sqlx(from = "String")] - path: String, - // #[sqlx(from = "i64")] - file_size: i32, - file_hash: String, -} - -#[derive(sqlx::FromRow)] -pub struct Composer { - name: String, - id: u32, -} - -impl Sheet { - pub fn new_debug() -> Self { - Sheet { - name: "Hello world".to_string(), - path: "This/is/my/path".into(), - file_size: 42, - file_hash: "h4sh".to_string(), - } - } - - pub fn verify_path(&self) -> std::io::Result { - // First compare file size since it is faster than hashing - // let file_size = fs::metadata(&self.path)?.len(); - // if file_size == self.file_size { - // let file_content = fs::read(&self.path)?; - // let file_hash = blake3::hash(&file_content); - // if file_hash.to_string() == self.file_hash { - // return Ok(true); - // } - // } - - Ok(false) - } -} +use crate::sheet::Sheet; pub struct Database { connection: SqlitePool, diff --git a/src/main.rs b/src/main.rs index e04e351..042dc8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ mod database; mod mcdu; +mod sheet; mod sheet_listing; -use std::{env, path::PathBuf, process}; +use std::{path::PathBuf, process}; use clap::Parser; use database::Database; @@ -13,8 +14,6 @@ use mcdu::McduModel; use relm4::prelude::*; use sheet_listing::{SheetListingInput, SheetListingModel}; -use crate::database::Sheet; - struct AppModel { mcdu: Controller, sheet_listing: Controller, diff --git a/src/sheet.rs b/src/sheet.rs new file mode 100644 index 0000000..82fa946 --- /dev/null +++ b/src/sheet.rs @@ -0,0 +1,40 @@ +#[derive(sqlx::FromRow, Debug)] +pub struct Sheet { + pub name: String, + // #[sqlx(from = "String")] + pub path: String, + // #[sqlx(from = "i64")] + pub file_size: i32, + pub file_hash: String, +} + +#[derive(sqlx::FromRow)] +pub struct Composer { + pub name: String, + pub id: u32, +} + +impl Sheet { + pub fn new_debug() -> Self { + Sheet { + name: "Hello world".to_string(), + path: "This/is/my/path".into(), + file_size: 42, + file_hash: "h4sh".to_string(), + } + } + + pub fn verify_path(&self) -> std::io::Result { + // First compare file size since it is faster than hashing + // let file_size = fs::metadata(&self.path)?.len(); + // if file_size == self.file_size { + // let file_content = fs::read(&self.path)?; + // let file_hash = blake3::hash(&file_content); + // if file_hash.to_string() == self.file_hash { + // return Ok(true); + // } + // } + + Ok(false) + } +}