Environment variables at runtime to connect to database
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use secrecy::ExposeSecret;
|
||||
use sqlx::{Executor, PgPool};
|
||||
use sqlx::{Connection, Executor, PgConnection, PgPool};
|
||||
use tokio::net::TcpListener;
|
||||
use uuid::Uuid;
|
||||
use zero2prod::{
|
||||
@@ -112,7 +111,7 @@ async fn spawn_app() -> TestApp {
|
||||
}
|
||||
|
||||
async fn configure_database(config: &DatabaseSettings) -> PgPool {
|
||||
let connection = PgPool::connect(config.connection_string_without_db().expose_secret())
|
||||
let mut connection = PgConnection::connect_with(&config.without_db())
|
||||
.await
|
||||
.expect("Failed to connect to Postgres");
|
||||
connection
|
||||
@@ -120,7 +119,7 @@ async fn configure_database(config: &DatabaseSettings) -> PgPool {
|
||||
.await
|
||||
.expect("Failed to create the database");
|
||||
|
||||
let connection_pool = PgPool::connect(config.connection_string().expose_secret())
|
||||
let connection_pool = PgPool::connect_with(config.with_db())
|
||||
.await
|
||||
.expect("Failed to connect to Postgres");
|
||||
sqlx::migrate!("./migrations")
|
||||
|
||||
Reference in New Issue
Block a user