Quantcast
Channel: How to set up a database connection from environment in Rocket? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by BergerBytes for How to set up a database connection from environment in Rocket?

$
0
0

The accepted answer works, but if you wanted to avoid needing a special formatted environment variable for rocket, you can also update the figment prior to starting rocket.

For example:

#[launch]async fn rocket() -> _ {    let figment = rocket::Config::figment().merge(("databases.my_db.url",        env::var("DATABASE_URL").expect("DATABASE_URL must be set"),    ));    rocket::custom(figment) // equivalent to rocket::build()}

Viewing all articles
Browse latest Browse all 4

Trending Articles