Skip to content

How to run custom init code on a database connection? #2441

Answered by elibroftw
elibroftw asked this question in Questions
Discussion options

You must be logged in to vote
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)
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by elibroftw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant