create DB::init function

semantically, its better to have function, that fully prepares db
(connect and migrate)
This commit is contained in:
Akulij 2025-04-27 21:02:05 +03:00
parent 29acb02a97
commit 09f7e76d96

View File

@ -94,6 +94,13 @@ impl DB {
.await?; .await?;
Ok(()) Ok(())
} }
pub async fn init<S: Into<String>>(db_url: S) -> Result<Self, mongodb::error::Error> {
let mut db = Self::new(db_url).await;
db.migrate().await?;
Ok(db)
}
} }
#[async_trait] #[async_trait]