Function with_database_config

Source
pub fn with_database_config<DB>(
    backend: DB,
    _config: DatabaseConfig,
) -> BoxedDatabaseEntryPoint<DB>
where DB: DatabaseBackend + Send + Sync + Debug + 'static,
Expand description

Database handlers for the testkit crate

This module provides handlers for database operations with the boxed API, which automatically handles boxing of closures to solve lifetime issues when capturing variables from the environment.

§Example:

use testkit_core::*;

async fn test() -> Result<(), Box<dyn std::error::Error>> {
    let backend = testkit_core::testdb::tests::MockBackend::new();
     
    // This local variable would cause lifetime issues with a non-boxed API
    let table_name = "users".to_string();
     
    let ctx = with_database(backend)
       .setup(|conn| boxed_async!(async move {
           // Can capture local variables without lifetime issues
           let query = format!("CREATE TABLE {}", table_name);
           // setup code
           Ok(())
       }))
       .with_transaction(|tx| boxed_async!(async move {
           // Transaction code with local variables
           Ok(())
       }))
       .execute()
       .await?;
    Ok(())
}

Create a new database entry point with the given backend and config

This function creates a new entry point for working with databases. Use the boxed_async! macro with setup and with_transaction to avoid lifetime issues.