Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow accessing state's internal pool #41

Closed
arcstur opened this issue May 12, 2024 · 3 comments
Closed

Allow accessing state's internal pool #41

arcstur opened this issue May 12, 2024 · 3 comments

Comments

@arcstur
Copy link
Contributor

arcstur commented May 12, 2024

Sometimes I need the pool, to construct other stuff in the application. It would be useful to access the state's internal pool, so that I don't need to have two of the same pool in my app's state. What do you think?

What I mean is that I don't want to have

#[derive(Clone, FromRef)]
pub struct AppState {
    pub pool: PgPool,
    pub tx_state: axum_sqlx_tx::State<sqlx::Postgres>,
}

And have only the tx_state, since it already holds a pool.

@connec
Copy link
Member

connec commented May 14, 2024

It would be possible to impl FromRef<axum_sqlx_tx::State<DB>> for sqlx::Pool<DB>, meaning a State<PgPool> could be extracted from an axum_sqlx_tx::State<sqlx::Postgres>.

Would that work for your use-case?

If you already needed a separate state struct, you'd have to proxy the FromRef implementation manually.

@arcstur
Copy link
Contributor Author

arcstur commented May 14, 2024

Yeah, that would be awesome! Then, in my state struct, I would do fn pool(&self) { PgPool::from_ref(&self.tx_state) }

@connec
Copy link
Member

connec commented May 15, 2024

Fixed by #42.

@connec connec closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants