Skip to content

Multiple Databases #464

Answered by kaplanelad
LimpidCrypto asked this question in Q&A
Feb 27, 2024 · 1 comments · 6 replies
Discussion options

You must be logged in to vote

Hey @LimpidCrypto
In your APP hooks, navigate to the after_routes function and implementing the following example:

   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>

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@LimpidCrypto
Comment options

@kaplanelad
Comment options

@LimpidCrypto
Comment options

@LimpidCrypto
Comment options

@LimpidCrypto
Comment options

Answer selected by LimpidCrypto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants