Merge pull request #5 from EETagent/db_url_as_env_var

refactor: use DATABASE_URL env variable instead of url var in Rocket.toml
This commit is contained in:
Sebastian Pravda 2022-10-24 16:55:44 +02:00 committed by GitHub
commit dfacf9ac83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -12,6 +12,7 @@ futures-util = { version = "^0.3" }
rocket = { version = "0.5.0-rc.2", features = [
"json",
] }
dotenv = "0.15.0"
serde_json = { version = "^1" }

View file

@ -21,15 +21,21 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
type Connection = sea_orm::DatabaseConnection;
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
let config = figment.extract::<Config>().unwrap();
let mut options: ConnectOptions = config.url.into();
dotenv::dotenv().ok();
let database_url = std::env::var("DATABASE_URL").unwrap();
let mut options: ConnectOptions = database_url.into();
options
.max_connections(1024)
.min_connections(0)
.connect_timeout(Duration::from_secs(3));
/* options
.max_connections(config.max_connections as u32)
.min_connections(config.min_connections.unwrap_or_default())
.connect_timeout(Duration::from_secs(config.connect_timeout));
if let Some(idle_timeout) = config.idle_timeout {
options.idle_timeout(Duration::from_secs(idle_timeout));
}
} */
let conn = sea_orm::Database::connect(options).await?;
Ok(SeaOrmPool { conn })