summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
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)