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 = "libsql")]
17use deadpool_libsql::Pool as DeadpoolLibsqlPool;
18#[cfg(feature = "turso")]
19use turso::Database as TursoDatabase;
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    /// `LibSQL` connection pool
39    #[cfg(feature = "libsql")]
40    Libsql(DeadpoolLibsqlPool),
41    /// `Turso` pseudo-pool (Database handle)
42    #[cfg(feature = "turso")]
43    Turso(TursoDatabase),
44}
45
46// Manual Debug implementation because not all pool types expose `Debug`
47impl std::fmt::Debug for MiddlewarePool {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        match self {
50            #[cfg(feature = "postgres")]
51            Self::Postgres(pool) => f.debug_tuple("Postgres").field(pool).finish(),
52            #[cfg(feature = "sqlite")]
53            Self::Sqlite(pool) => f.debug_tuple("Sqlite").field(pool).finish(),
54            #[cfg(feature = "mssql")]
55            Self::Mssql(_) => f.debug_tuple("Mssql").field(&"<TiberiusPool>").finish(),
56            #[cfg(feature = "libsql")]
57            Self::Libsql(pool) => f.debug_tuple("Libsql").field(pool).finish(),
58            #[cfg(feature = "turso")]
59            Self::Turso(_) => f.debug_tuple("Turso").field(&"<Database>").finish(),
60        }
61    }
62}
63
64impl MiddlewarePool {
65    /// Return a reference to self instead of cloning the entire pool
66    ///
67    /// # Errors
68    /// This function currently never returns an error but maintains Result for API consistency.
69    #[allow(clippy::unused_async)]
70    pub async fn get(&self) -> Result<&MiddlewarePool, SqlMiddlewareDbError> {
71        Ok(self)
72    }
73}