Multiple Databases #464
-
I have a SaaS1 with a Database hosted locally using Docker. I also have another SaaS2 which is pretty similar to the SaaS1. It also has a Database. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hey @LimpidCrypto async fn after_routes(router: axum::Router, _ctx: &AppContext) -> Result<axum::Router> {
let saas2_db_config = config::Database {
// ... (fill in your configuration details)
};
let saas2_db = db::connect(&saas_db_config).await?;
Ok(router.layer(Extension(saas2_db)))
} In this illustration, we use a local DB configuration and integrate the database connection as an Axum extension. Now, in your controller, retrieve this instance using the following example: async fn example(
_auth: auth::JWT,
State(_ctx): State<AppContext>,
Extension(saas2_db): Extension<DatabaseConnection>,
) -> Result<()> {
...
} Define the extension in the controller's schema function, and you'll be able to seamlessly utilize the secondary database. |
Beta Was this translation helpful? Give feedback.
Hey @LimpidCrypto
In your
APP
hooks, navigate to theafter_routes
function and implementing the following example:In this illustration, we use a local DB configuration and integrate the database connection as an Axum extension.
Now, in your controller, retrieve this instance using the following example: