Replies: 1 comment
-
use rocket::fairing::AdHoc;
use rocket::{Build, Rocket};
.attach(AdHoc::try_on_ignite("Create collection indexes", create_indexes))
pub async fn create_indexes(rocket: Rocket<Build>) -> fairing::Result {
if let Some(db) = MainDatabase::fetch(&rocket) {
return Ok(rocket);
}
Err(rocket)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
elibroftw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Suppose I have a database
ApiDatabase
which is attached via.attach(ApiDatabase.init())
.What is the best or simplest manner to run code on rocket startup that utilizes this database connection?
Beta Was this translation helpful? Give feedback.
All reactions