Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split DB_URL into separate vars #229

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion fplus-database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ pub fn init() {
* @return Result<DatabaseConnection, sea_orm::DbErr> - The result of the operation
*/
pub async fn setup() -> Result<(), DbErr> {
let database_url = get_env_or_throw("DB_URL");
let database_url = std::env::var("DB_URL").unwrap_or_else(|_| {
format!(
"postgres://{}:{}@{}:{}/{}?{}",
get_env_or_throw("DB_USER"),
get_env_or_throw("DB_PASS"),
get_env_or_throw("DB_HOST"),
std::env::var("DB_PORT").unwrap_or("5432".into()),
get_env_or_throw("DB_NAME"),
std::env::var("DB_OPTIONS").unwrap_or_default()
)
});
let db_conn = Database::connect(&database_url).await?;
let mut db_conn_global = DB_CONN.lock().unwrap();
*db_conn_global = Some(db_conn);
Expand Down