sql_middleware/pool/
types.rs

1#[cfg(feature = "postgres")]
2use deadpool_postgres::Pool as DeadpoolPostgresPool;
3
4#[cfg(feature = "sqlite")]
5use deadpool_sqlite::Pool as DeadpoolSqlitePool;
6
7#[cfg(feature = "sqlite")]
8pub type SqliteWritePool = DeadpoolSqlitePool;
9
10#[cfg(feature = "mssql")]
11use deadpool_tiberius::Pool as TiberiusPool;
12
13#[cfg(feature = "libsql")]
14use deadpool_libsql::Pool as DeadpoolLibsqlPool;
15#[cfg(feature = "turso")]
16use turso::Database as TursoDatabase;
17
18use crate::error::SqlMiddlewareDbError;
19
20/// Connection pool for database access
21///
22/// This enum wraps the different connection pool types for the
23/// supported database engines.
24#[derive(Clone)]
25pub enum MiddlewarePool {
26    /// `PostgreSQL` connection pool
27    #[cfg(feature = "postgres")]
28    Postgres(DeadpoolPostgresPool),
29    /// `SQLite` connection pool
30    #[cfg(feature = "sqlite")]
31    Sqlite(DeadpoolSqlitePool),
32    /// SQL Server connection pool
33    #[cfg(feature = "mssql")]
34    Mssql(TiberiusPool),
35    /// `LibSQL` connection pool
36    #[cfg(feature = "libsql")]
37    Libsql(DeadpoolLibsqlPool),
38    /// `Turso` pseudo-pool (Database handle)
39    #[cfg(feature = "turso")]
40    Turso(TursoDatabase),
41}
42
43// Manual Debug implementation because deadpool_tiberius::Manager doesn't implement 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 = "libsql")]
54            Self::Libsql(pool) => f.debug_tuple("Libsql").field(pool).finish(),
55            #[cfg(feature = "turso")]
56            Self::Turso(_) => f.debug_tuple("Turso").field(&"<Database>").finish(),
57        }
58    }
59}
60
61impl MiddlewarePool {
62    /// Return a reference to self instead of cloning the entire pool
63    ///
64    /// # Errors
65    /// This function currently never returns an error but maintains Result for API consistency.
66    #[allow(clippy::unused_async)]
67    pub async fn get(&self) -> Result<&MiddlewarePool, SqlMiddlewareDbError> {
68        Ok(self)
69    }
70}