diff options
Diffstat (limited to 'src/database/mod.rs')
-rw-r--r-- | src/database/mod.rs | 34 |
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 }) + } +} + |