From 57a2df34f4986f1f6062f22804021925afec0419 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Sat, 25 Jan 2025 20:50:21 +0100 Subject: refactor database --- src/database/mod.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/database/mod.rs (limited to 'src/database/mod.rs') diff --git a/src/database/mod.rs b/src/database/mod.rs new file mode 100644 index 0000000..d66b72b --- /dev/null +++ b/src/database/mod.rs @@ -0,0 +1,34 @@ +pub mod song; +pub mod album; +pub mod artist; +pub mod search_results; + +use serde::{Deserialize, Serialize}; +use sqlx::mysql::{MySqlPool, MySqlPoolOptions}; +use std::env; + +#[derive(Serialize, Deserialize)] +pub struct Delete { + pub id: Option, +} + +pub struct DatabaseWrapper { + db_pool: MySqlPool, +} + +impl DatabaseWrapper { + pub async fn new() -> Result { + let pool: MySqlPool = MySqlPoolOptions::new() + .max_connections(10) + .connect( + env::var("DATABASE_URL") + .expect("Environment variable DATABASE_URL is *probably not setted up!!") + .as_str(), + ) + .await + .unwrap(); /* This will break in case of error. It's intended. */ + + Ok(DatabaseWrapper { db_pool: pool }) + } +} + -- cgit v1.2.3