pub trait DbConnection: Send + Sync {
// Required methods
fn execute_sql<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn query_map<'life0, 'life1, 'async_trait, T>(
&'life0 self,
sql: &'life1 str,
params: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DbError>> + Send + 'async_trait>>
where T: 'async_trait + FromRow + Send + 'static,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Trait abstracting over database connections for testability and driver swaps.
Query functions accept &(impl DbConnection) so callers can provide
any backend (libsql, rusqlite, postgres) or a test double.
All methods are async. Sync backends (rusqlite) use spawn_blocking
internally to satisfy the async interface.
Required Methods§
Sourcefn execute_sql<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_sql<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute a write statement (INSERT/UPDATE/DELETE) and return affected row count.
Parameters are passed as Vec<Value> and converted to the driver’s
native parameter type by each backend implementation.
§Errors
Returns DbError::Query if the SQL execution fails.
Sourcefn query_map<'life0, 'life1, 'async_trait, T>(
&'life0 self,
sql: &'life1 str,
params: Vec<Value>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DbError>> + Send + 'async_trait>>
fn query_map<'life0, 'life1, 'async_trait, T>( &'life0 self, sql: &'life1 str, params: Vec<Value>, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DbError>> + Send + 'async_trait>>
Execute a SELECT statement and map each row into T via FromRow.
§Errors
Returns DbError::Query if the SQL execution fails or DbError::RowMapping
if a row cannot be converted into T.
Sourcefn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute a batch of SQL statements (e.g., DDL, migrations).
The batch is executed as a single string. Backends that require statement-level execution must split internally.
§Errors
Returns DbError::Query if any statement in the batch fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".