All checks were successful
Reviewed-on: #65 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
37 lines
997 B
Rust
37 lines
997 B
Rust
// TODO: Get rid of this file and place the code in more appropriate places
|
|
pub mod callers;
|
|
pub mod config;
|
|
pub mod hashing;
|
|
pub mod repo;
|
|
pub mod token_stuff;
|
|
|
|
mod connection_settings {
|
|
pub const MAXCONN: u32 = 5;
|
|
}
|
|
|
|
pub mod db {
|
|
|
|
use sqlx::postgres::PgPoolOptions;
|
|
|
|
use crate::connection_settings;
|
|
|
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
|
let database_url = icarus_envy::environment::get_db_url().await.value;
|
|
println!("Database url: {database_url}");
|
|
|
|
PgPoolOptions::new()
|
|
.max_connections(connection_settings::MAXCONN)
|
|
.connect(&database_url)
|
|
.await
|
|
}
|
|
|
|
pub async fn migrations(pool: &sqlx::PgPool) {
|
|
// Run migrations using the sqlx::migrate! macro
|
|
// Assumes your migrations are in a ./migrations folder relative to Cargo.toml
|
|
sqlx::migrate!("./migrations")
|
|
.run(pool)
|
|
.await
|
|
.expect("Failed to run migrations");
|
|
}
|
|
}
|