Skip to main content

premix_orm/integrations/
axum.rs

1use axum::extract::FromRef;
2
3/// Axum state wrapper for Premix pools.
4#[derive(Clone, Debug)]
5pub struct PremixState<DB: sqlx::Database> {
6    /// The database connection pool.
7    pub pool: sqlx::Pool<DB>,
8}
9
10impl<DB: sqlx::Database> PremixState<DB> {
11    /// Creates a new `PremixState` with the given pool.
12    pub fn new(pool: sqlx::Pool<DB>) -> Self {
13        Self { pool }
14    }
15}
16
17impl<DB: sqlx::Database> FromRef<PremixState<DB>> for sqlx::Pool<DB> {
18    fn from_ref(state: &PremixState<DB>) -> Self {
19        state.pool.clone()
20    }
21}