Skip to main content

sql_middleware/pool/
types.rs

1#[cfg(feature = "postgres")]
2use crate::postgres::typed::PgManager;
3#[cfg(feature = "postgres")]
4use bb8::Pool as PostgresPool;
5
6#[cfg(feature = "sqlite")]
7use crate::sqlite::config::SqliteManager;
8#[cfg(feature = "sqlite")]
9use bb8::Pool as Bb8SqlitePool;
10
11#[cfg(feature = "mssql")]
12use bb8::Pool as Bb8MssqlPool;
13#[cfg(feature = "mssql")]
14use bb8_tiberius::ConnectionManager;
15
16#[cfg(feature = "turso")]
17use crate::turso::typed::TursoManager;
18#[cfg(feature = "turso")]
19use bb8::Pool as Bb8TursoPool;
20
21use crate::error::SqlMiddlewareDbError;
22
23/// Connection pool for database access
24///
25/// This enum wraps the different connection pool types for the
26/// supported database engines.
27#[derive(Clone)]
28pub enum MiddlewarePool {
29    /// `PostgreSQL` connection pool
30    #[cfg(feature = "postgres")]
31    Postgres(PostgresPool<PgManager>),
32    /// `SQLite` connection pool
33    #[cfg(feature = "sqlite")]
34    Sqlite(Bb8SqlitePool<SqliteManager>),
35    /// SQL Server connection pool
36    #[cfg(feature = "mssql")]
37    Mssql(Bb8MssqlPool<ConnectionManager>),
38    /// `Turso` connection pool
39    #[cfg(feature = "turso")]
40    Turso(Bb8TursoPool<TursoManager>),
41}
42
43// Manual Debug implementation because not all pool types expose `Debug`
44impl std::fmt::Debug for MiddlewarePool {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        match self {
47            #[cfg(feature = "postgres")]
48            Self::Postgres(pool) => f.debug_tuple("Postgres").field(pool).finish(),
49            #[cfg(feature = "sqlite")]
50            Self::Sqlite(pool) => f.debug_tuple("Sqlite").field(pool).finish(),
51            #[cfg(feature = "mssql")]
52            Self::Mssql(_) => f.debug_tuple("Mssql").field(&"<TiberiusPool>").finish(),
53            #[cfg(feature = "turso")]
54            Self::Turso(pool) => f.debug_tuple("Turso").field(pool).finish(),
55        }
56    }
57}
58
59impl MiddlewarePool {
60    /// Return a reference to self instead of cloning the entire pool
61    ///
62    /// # Errors
63    /// This function currently never returns an error but maintains Result for API consistency.
64    #[allow(clippy::unused_async)]
65    pub async fn get(&self) -> Result<&MiddlewarePool, SqlMiddlewareDbError> {
66        Ok(self)
67    }
68}