Files
soaricarus_api/src/db/mod.rs
T
KDandGitHub 1b9bd4359c tsk-207: Move code elsewhere that is found in src/main.rs (#242)
* tsk-207: Move code elsewhere that is found in src/main.rs

* tsk-207: Some refactoring

* tsk-207: Moving file around

* tsk-207: Code formatting

* tsk-207: Version bump

* tsk-207: Test fix
2025-11-04 11:19:12 -05:00

25 lines
719 B
Rust

use sqlx::postgres::PgPoolOptions;
pub mod connection_settings {
pub const MAXCONN: u32 = 10;
}
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");
}