sql_middleware/pool/
mod.rs

1pub mod connection;
2pub mod interaction;
3pub mod types;
4
5pub use connection::MiddlewarePoolConnection;
6pub use types::{MiddlewarePool, SqliteWritePool};
7
8use crate::SqlMiddlewareDbError;
9use crate::types::DatabaseType;
10
11/// Configuration and connection pool for a database
12///
13/// This struct holds both the configuration and the connection pool
14/// for a database, making it easier to manage database connections.
15#[derive(Clone, Debug)]
16pub struct ConfigAndPool {
17    /// The connection pool
18    pub pool: MiddlewarePool,
19    /// The database type
20    pub db_type: DatabaseType,
21    /// Whether placeholder translation is enabled by default for this pool
22    pub translate_placeholders: bool,
23}
24
25impl ConfigAndPool {
26    /// Get a pooled connection and attach pool-level defaults to it.
27    ///
28    /// # Errors
29    /// Bubbles up pool checkout errors for the active backend.
30    pub async fn get_connection(&self) -> Result<MiddlewarePoolConnection, SqlMiddlewareDbError> {
31        let pool_ref = self.pool.get().await?;
32        MiddlewarePool::get_connection(pool_ref, self.translate_placeholders).await
33    }
34}