working proto

This commit is contained in:
Romulus21
2024-09-28 00:52:51 +02:00
parent 9bc48ff63d
commit 72b65063be
20 changed files with 1706 additions and 1569 deletions

26
src/database.rs Normal file
View File

@@ -0,0 +1,26 @@
static DB: std::sync::OnceLock<sqlx::MySqlPool> = std::sync::OnceLock::new();
async fn create_pool() -> sqlx::MySqlPool {
let database_url = std::env::var("DATABASE_URL").expect("no database url specify");
dbg!(&database_url);
let pool = sqlx::mysql::MySqlPoolOptions::new()
.max_connections(4)
.connect(database_url.as_str())
.await
.expect("could not connect to database_url");
sqlx::migrate!()
.run(&pool)
.await
.expect("migrations failed");
pool
}
pub async fn init_db() -> Result<(), sqlx::Pool<sqlx::MySql>> {
DB.set(create_pool().await)
}
pub fn get_db<'a>() -> &'a sqlx::MySqlPool {
DB.get().expect("database unitialized")
}