summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-19 18:04:33 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-19 18:04:33 +0100
commited0f5925de1931a13e6713d73e174a5362fc5d68 (patch)
treeb7d6e2e6db726a3cfff2358afade70da682d5e0f /src/main.rs
parent95b944b819d7a1320d3083929177676f93d4a3e3 (diff)
database rework update (uncomplete, broken)
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index bddb0b6..f1a58ec 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,34 +1,25 @@
mod routes;
mod structs;
+mod database;
use actix_web::{web, App, HttpServer};
use dotenv::dotenv;
-use sqlx::mysql::{MySqlPool, MySqlPoolOptions};
-use std::env;
+use std::sync::Arc;
-#[derive(Clone)]
struct AppState {
- pool: MySqlPool,
+ database: database::DatabaseWrapper
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
- let pool: MySqlPool = MySqlPoolOptions::new()
- .max_connections(10)
- .connect(
- env::var("DATABASE_URL")
- .expect("environment variables are *probably not setted up!!")
- .as_str(),
- )
- .await
- .unwrap();
- let app_state = AppState { pool };
+ let app_state_raw = database::DatabaseWrapper::new().await.expect("Something went wrong -- DatabaseWrapper::new()");
+ let app_state = Arc::new(app_state_raw);
HttpServer::new(move || {
App::new()
- .app_data(web::Data::new(app_state.clone()))
+ .app_data(web::Data::new(Arc::clone(&app_state)))
.route("/", web::get().to(root))
.service(routes::song::song)
.service(routes::album::album)