mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 05:51:56 +00:00
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:
commit
dfacf9ac83
2 changed files with 10 additions and 3 deletions
|
|
@ -12,6 +12,7 @@ futures-util = { version = "^0.3" }
|
||||||
rocket = { version = "0.5.0-rc.2", features = [
|
rocket = { version = "0.5.0-rc.2", features = [
|
||||||
"json",
|
"json",
|
||||||
] }
|
] }
|
||||||
|
dotenv = "0.15.0"
|
||||||
|
|
||||||
serde_json = { version = "^1" }
|
serde_json = { version = "^1" }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,21 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
|
||||||
type Connection = sea_orm::DatabaseConnection;
|
type Connection = sea_orm::DatabaseConnection;
|
||||||
|
|
||||||
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
|
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
|
||||||
let config = figment.extract::<Config>().unwrap();
|
dotenv::dotenv().ok();
|
||||||
let mut options: ConnectOptions = config.url.into();
|
let database_url = std::env::var("DATABASE_URL").unwrap();
|
||||||
|
let mut options: ConnectOptions = database_url.into();
|
||||||
options
|
options
|
||||||
|
.max_connections(1024)
|
||||||
|
.min_connections(0)
|
||||||
|
.connect_timeout(Duration::from_secs(3));
|
||||||
|
|
||||||
|
/* options
|
||||||
.max_connections(config.max_connections as u32)
|
.max_connections(config.max_connections as u32)
|
||||||
.min_connections(config.min_connections.unwrap_or_default())
|
.min_connections(config.min_connections.unwrap_or_default())
|
||||||
.connect_timeout(Duration::from_secs(config.connect_timeout));
|
.connect_timeout(Duration::from_secs(config.connect_timeout));
|
||||||
if let Some(idle_timeout) = config.idle_timeout {
|
if let Some(idle_timeout) = config.idle_timeout {
|
||||||
options.idle_timeout(Duration::from_secs(idle_timeout));
|
options.idle_timeout(Duration::from_secs(idle_timeout));
|
||||||
}
|
} */
|
||||||
let conn = sea_orm::Database::connect(options).await?;
|
let conn = sea_orm::Database::connect(options).await?;
|
||||||
|
|
||||||
Ok(SeaOrmPool { conn })
|
Ok(SeaOrmPool { conn })
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue