From cc27ab5b6ddff27b32312025fed03d8467168980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= <tm@tlater.net> Date: Fri, 28 Mar 2025 21:55:08 +0800 Subject: [PATCH] refactor(card_database): Accurately name card database --- src/bin/database_worker.rs | 4 ++-- src/{database.rs => card_database.rs} | 10 +++++----- src/{database => card_database}/models.rs | 4 ++-- src/{database => card_database}/schema.rs | 0 src/{database => card_database}/worker.rs | 6 +++--- src/components/card.rs | 2 +- src/lib.rs | 2 +- src/main.rs | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) rename src/{database.rs => card_database.rs} (88%) rename src/{database => card_database}/models.rs (97%) rename src/{database => card_database}/schema.rs (100%) rename src/{database => card_database}/worker.rs (97%) diff --git a/src/bin/database_worker.rs b/src/bin/database_worker.rs index 3a99853..44872d8 100644 --- a/src/bin/database_worker.rs +++ b/src/bin/database_worker.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU Affero General Public License // along with yugioh-binder. If not, see <https://www.gnu.org/licenses/>. -use draft_manager::database::BrowserDatabase; +use draft_manager::card_database::CardDatabase; fn main() { console_error_panic_hook::set_once(); wasm_logger::init(wasm_logger::Config::default()); wasm_bindgen_futures::spawn_local(async { - let a = BrowserDatabase::init_worker().await; + let a = CardDatabase::init_worker().await; if let Err(e) = a { log::error!("{:?}", e); diff --git a/src/database.rs b/src/card_database.rs similarity index 88% rename from src/database.rs rename to src/card_database.rs index 406f998..3ff5af8 100644 --- a/src/database.rs +++ b/src/card_database.rs @@ -20,13 +20,13 @@ pub mod models; pub mod schema; mod worker; -use worker::{BrowserDatabaseError, DatabaseWorker, Query}; +use worker::{CardDatabaseWorkerError, DatabaseWorker, Query}; -pub struct BrowserDatabase { +pub struct CardDatabase { worker: WorkerBridge<DatabaseWorker>, } -impl BrowserDatabase { +impl CardDatabase { pub fn new() -> Self { let bridge = DatabaseWorker::spawner() .callback(move |o| { @@ -46,7 +46,7 @@ impl BrowserDatabase { /// Initialize the database worker. /// /// Must be executed in a worker script, not on the main thread. - pub async fn init_worker() -> Result<(), BrowserDatabaseError> { + pub async fn init_worker() -> Result<(), CardDatabaseWorkerError> { log::debug!("Initializing database worker..."); DatabaseWorker::initialize_db().await?; DatabaseWorker::registrar().register(); @@ -55,7 +55,7 @@ impl BrowserDatabase { } } -impl Default for BrowserDatabase { +impl Default for CardDatabase { fn default() -> Self { Self::new() } diff --git a/src/database/models.rs b/src/card_database/models.rs similarity index 97% rename from src/database/models.rs rename to src/card_database/models.rs index 1fdd7b9..a6482a1 100644 --- a/src/database/models.rs +++ b/src/card_database/models.rs @@ -17,8 +17,8 @@ use diesel::prelude::*; use serde::{Deserialize, Serialize}; -use crate::database::schema::datas; -use crate::database::schema::texts; +use super::schema::datas; +use super::schema::texts; #[derive(Debug, Selectable, Queryable)] #[diesel(table_name = datas)] diff --git a/src/database/schema.rs b/src/card_database/schema.rs similarity index 100% rename from src/database/schema.rs rename to src/card_database/schema.rs diff --git a/src/database/worker.rs b/src/card_database/worker.rs similarity index 97% rename from src/database/worker.rs rename to src/card_database/worker.rs index 6d6e253..88d03e0 100644 --- a/src/database/worker.rs +++ b/src/card_database/worker.rs @@ -160,7 +160,7 @@ async fn should_update_card_db() -> Result<bool> { let last_update = { let ts = read_opfs_file("last_update.txt").await?; if !ts.is_empty() { - OffsetDateTime::parse(&ts, &Rfc3339).map_err(BrowserDatabaseError::from) + OffsetDateTime::parse(&ts, &Rfc3339).map_err(CardDatabaseWorkerError::from) } else { Ok(OffsetDateTime::UNIX_EPOCH) } @@ -193,7 +193,7 @@ async fn update_card_db(sah_pool_util: &OpfsSAHPoolUtil) -> Result<()> { } #[derive(Debug, Error)] -pub enum BrowserDatabaseError { +pub enum CardDatabaseWorkerError { #[error("failed to connect to database")] DieselConnectionError(#[from] diesel::ConnectionError), #[error("failed to query database")] @@ -210,4 +210,4 @@ pub enum BrowserDatabaseError { #[error("failed to write last Babel DB update date")] TimeFormatError(#[from] time::error::Format), } -type Result<T> = std::result::Result<T, BrowserDatabaseError>; +type Result<T> = std::result::Result<T, CardDatabaseWorkerError>; diff --git a/src/components/card.rs b/src/components/card.rs index a1826c0..c87281c 100644 --- a/src/components/card.rs +++ b/src/components/card.rs @@ -16,7 +16,7 @@ // along with yugioh-binder. If not, see <https://www.gnu.org/licenses/>. use leptos::prelude::*; -use crate::database::models::CardData; +use crate::card_database::models::CardData; #[component] pub fn Card(details: Option<CardData>) -> impl IntoView { diff --git a/src/lib.rs b/src/lib.rs index 215529c..473c4fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU Affero General Public License // along with yugioh-binder. If not, see <https://www.gnu.org/licenses/>. +pub mod card_database; pub mod components; -pub mod database; pub mod draft_list; pub mod utils; diff --git a/src/main.rs b/src/main.rs index 522294b..b054981 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ // along with yugioh-binder. If not, see <https://www.gnu.org/licenses/>. use std::time::Duration; -use draft_manager::database::BrowserDatabase; +use draft_manager::card_database::CardDatabase; use leptos::prelude::*; use wasm_bindgen_futures::spawn_local; @@ -25,7 +25,7 @@ fn main() { wasm_logger::init(wasm_logger::Config::default()); log::debug!("Startin app database"); - let db = BrowserDatabase::new(); + let db = CardDatabase::new(); log::debug!("Database initialized"); leptos::mount::mount_to_body(|| view! { <App /> });