-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into clean-starters
- Loading branch information
Showing
9 changed files
with
88 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use async_trait::async_trait; | ||
use axum::{Extension, Router as AxumRouter}; | ||
|
||
use crate::{ | ||
app::{AppContext, Initializer}, | ||
db, Error, Result, | ||
}; | ||
|
||
#[allow(clippy::module_name_repetitions)] | ||
pub struct ExtraDbInitializer; | ||
|
||
#[async_trait] | ||
impl Initializer for ExtraDbInitializer { | ||
fn name(&self) -> String { | ||
"extra_db".to_string() | ||
} | ||
|
||
async fn after_routes(&self, router: AxumRouter, ctx: &AppContext) -> Result<AxumRouter> { | ||
let extra_db_config = ctx | ||
.config | ||
.initializers | ||
.clone() | ||
.ok_or_else(|| Error::Message("initializers config not configured".to_string()))?; | ||
|
||
let extra_db_value = extra_db_config | ||
.get("extra_db") | ||
.ok_or_else(|| Error::Message("initializers config not configured".to_string()))?; | ||
|
||
let extra_db = serde_json::from_value(extra_db_value.clone())?; | ||
|
||
let db = db::connect(&extra_db).await?; | ||
Ok(router.layer(Extension(db))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[cfg(feature = "with-db")] | ||
pub mod extra_db; | ||
|
||
#[cfg(feature = "with-db")] | ||
pub mod multi_db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use async_trait::async_trait; | ||
use axum::{Extension, Router as AxumRouter}; | ||
|
||
use crate::{ | ||
app::{AppContext, Initializer}, | ||
db, Error, Result, | ||
}; | ||
|
||
#[allow(clippy::module_name_repetitions)] | ||
pub struct MultiDbInitializer; | ||
|
||
#[async_trait] | ||
impl Initializer for MultiDbInitializer { | ||
fn name(&self) -> String { | ||
"multi_db".to_string() | ||
} | ||
|
||
async fn after_routes(&self, router: AxumRouter, ctx: &AppContext) -> Result<AxumRouter> { | ||
let settings = ctx | ||
.config | ||
.initializers | ||
.clone() | ||
.ok_or_else(|| Error::Message("settings config not configured".to_string()))?; | ||
|
||
let multi_db = settings | ||
.get("multi_db") | ||
.ok_or_else(|| Error::Message("multi_db not configured".to_string()))?; | ||
|
||
let multi_db = db::MultiDb::new(serde_json::from_value(multi_db.clone())?).await?; | ||
Ok(router.layer(Extension(multi_db))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters