pub struct ConfigAndPool {
pub pool: MiddlewarePool,
pub db_type: DatabaseType,
pub translate_placeholders: bool,
}Expand description
Configuration and connection pool for a database
This struct holds both the configuration and the connection pool for a database, making it easier to manage database connections.
Fields§
§pool: MiddlewarePoolThe connection pool
db_type: DatabaseTypeThe database type
translate_placeholders: boolWhether placeholder translation is enabled by default for this pool
Implementations§
Source§impl ConfigAndPool
impl ConfigAndPool
Sourcepub async fn get_connection(
&self,
) -> Result<MiddlewarePoolConnection, SqlMiddlewareDbError>
pub async fn get_connection( &self, ) -> Result<MiddlewarePoolConnection, SqlMiddlewareDbError>
Get a pooled connection and attach pool-level defaults to it.
§Errors
Bubbles up pool checkout errors for the active backend.
Source§impl ConfigAndPool
impl ConfigAndPool
Sourcepub async fn new_postgres(
pg_config: PgConfig,
) -> Result<Self, SqlMiddlewareDbError>
pub async fn new_postgres( pg_config: PgConfig, ) -> Result<Self, SqlMiddlewareDbError>
Asynchronous initializer for ConfigAndPool with Postgres
§Errors
Returns SqlMiddlewareDbError::ConfigError if required config fields are missing or SqlMiddlewareDbError::ConnectionError if pool creation fails.
Sourcepub async fn new_postgres_with_translation(
pg_config: PgConfig,
translate_placeholders: bool,
) -> Result<Self, SqlMiddlewareDbError>
pub async fn new_postgres_with_translation( pg_config: PgConfig, translate_placeholders: bool, ) -> Result<Self, SqlMiddlewareDbError>
Asynchronous initializer for ConfigAndPool with Postgres and optional translation default.
§Errors
Returns SqlMiddlewareDbError::ConfigError if required config fields are missing or SqlMiddlewareDbError::ConnectionError if pool creation fails.
Warning: translation skips placeholders inside quoted strings, comments, and dollar-quoted blocks via a lightweight state machine; it may miss edge cases in complex SQL (e.g., PL/pgSQL bodies). Prefer backend-specific SQL instead of relying on translation:
let query = match &conn {
MiddlewarePoolConnection::Postgres { .. } => r#"$function$
BEGIN
RETURN ($1 ~ $q$[\t\r\n\v\\]$q$);
END;
$function$"#,
MiddlewarePoolConnection::Sqlite { .. } | MiddlewarePoolConnection::Turso { .. } => {
include_str!("../sql/functions/sqlite/03_sp_get_scores.sql")
}
};Source§impl ConfigAndPool
impl ConfigAndPool
Sourcepub async fn new_sqlite(db_path: String) -> Result<Self, SqlMiddlewareDbError>
pub async fn new_sqlite(db_path: String) -> Result<Self, SqlMiddlewareDbError>
Asynchronous initializer for ConfigAndPool with Sqlite using deadpool_sqlite
§Errors
Returns SqlMiddlewareDbError::ConnectionError if pool creation or connection test fails.
Sourcepub async fn new_sqlite_with_translation(
db_path: String,
translate_placeholders: bool,
) -> Result<Self, SqlMiddlewareDbError>
pub async fn new_sqlite_with_translation( db_path: String, translate_placeholders: bool, ) -> Result<Self, SqlMiddlewareDbError>
Asynchronous initializer for ConfigAndPool with Sqlite using deadpool_sqlite
and optional placeholder translation default.
§Errors
Returns SqlMiddlewareDbError::ConnectionError if pool creation or connection test fails.
Warning: translation skips placeholders inside quoted strings, comments, and dollar-quoted blocks via a lightweight state machine; it may miss edge cases in complex SQL. Prefer backend-specific SQL instead of relying on translation:
let query = match &conn {
MiddlewarePoolConnection::Postgres { .. } => r#"$function$
BEGIN
RETURN ($1 ~ $q$[\t\r\n\v\\]$q$);
END;
$function$"#,
MiddlewarePoolConnection::Sqlite { .. } | MiddlewarePoolConnection::Turso { .. } => {
include_str!("../sql/functions/sqlite/03_sp_get_scores.sql")
}
};Trait Implementations§
Source§impl Clone for ConfigAndPool
impl Clone for ConfigAndPool
Source§fn clone(&self) -> ConfigAndPool
fn clone(&self) -> ConfigAndPool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more