Skip to main content

DatabaseAdapter

Trait DatabaseAdapter 

Source
pub trait DatabaseAdapter: Send + Sync {
    // Required methods
    fn inspector(&self) -> Box<dyn SchemaInspector>;
    fn migration_runner(&self) -> Box<dyn MigrationRunner>;
    fn database_type(&self) -> &str;
    fn test_connection<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Main database adapter trait

This is the entry point for database operations. It provides:

  • Connection management
  • Factory methods for inspectors and runners
  • Database-specific configuration

Each database type (PostgreSQL, MySQL, etc.) implements this trait.

Required Methods§

Source

fn inspector(&self) -> Box<dyn SchemaInspector>

Get a schema inspector for this database

The inspector is used for read-only schema introspection.

Source

fn migration_runner(&self) -> Box<dyn MigrationRunner>

Get a migration runner for this database

The runner is used for executing schema changes.

Source

fn database_type(&self) -> &str

Get the database type identifier

Returns a string like “postgresql”, “mysql”, “sqlite”, etc.

Source

fn test_connection<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Test the database connection

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§