summaryrefslogtreecommitdiff
path: root/src/database/mod.rs
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-25 20:50:21 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-25 20:50:21 +0100
commit57a2df34f4986f1f6062f22804021925afec0419 (patch)
treef72ba12f40d15248d25235ce711b0aec2a6137a9 /src/database/mod.rs
parent8782579e326b55e182d5767a451b8864b3453cce (diff)
refactor database
Diffstat (limited to 'src/database/mod.rs')
-rw-r--r--src/database/mod.rs34
1 files changed, 34 insertions, 0 deletions
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<String>,
+}
+
+pub struct DatabaseWrapper {
+ db_pool: MySqlPool,
+}
+
+impl DatabaseWrapper {
+ pub async fn new() -> Result<DatabaseWrapper, sqlx::Error> {
+ 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 })
+ }
+}
+