Trait DatabaseBackend

Source
pub trait DatabaseBackend:
    Send
    + Sync
    + Clone
    + Debug {
    type Connection: Send + Sync + Clone;
    type Pool: Send + Sync + DatabasePool<Connection = Self::Connection, Error = Self::Error>;
    type Error: Send + Sync + Clone + From<String> + Display + Debug;

    // Required methods
    fn new<'async_trait>(
        config: DatabaseConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn create_pool<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        name: &'life1 DatabaseName,
        config: &'life2 DatabaseConfig,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Pool, Self::Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn connect_with_string<'life0, 'life1, 'async_trait>(
        &'life0 self,
        connection_string: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Connection, Self::Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn create_database<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        pool: &'life1 Self::Pool,
        name: &'life2 DatabaseName,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn drop_database(&self, name: &DatabaseName) -> Result<(), Self::Error>;
    fn connection_string(&self, name: &DatabaseName) -> String;

    // Provided method
    fn connect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        name: &'life1 DatabaseName,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Connection, Self::Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Re-export the traits from testkit-core Trait defining a test database abstraction

Required Associated Types§

Source

type Connection: Send + Sync + Clone

Source

type Pool: Send + Sync + DatabasePool<Connection = Self::Connection, Error = Self::Error>

Source

type Error: Send + Sync + Clone + From<String> + Display + Debug

Required Methods§

Source

fn new<'async_trait>( config: DatabaseConfig, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Source

fn create_pool<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 DatabaseName, config: &'life2 DatabaseConfig, ) -> Pin<Box<dyn Future<Output = Result<Self::Pool, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Create a new connection pool for the given database

Source

fn connect_with_string<'life0, 'life1, 'async_trait>( &'life0 self, connection_string: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Self::Connection, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Create a single connection using a connection string directly This is useful for connecting to databases that may not have been created by TestKit

Source

fn create_database<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, pool: &'life1 Self::Pool, name: &'life2 DatabaseName, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Create a new database with the given name

Source

fn drop_database(&self, name: &DatabaseName) -> Result<(), Self::Error>

Drop a database with the given name

Source

fn connection_string(&self, name: &DatabaseName) -> String

Get the connection string for the given database

Provided Methods§

Source

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 DatabaseName, ) -> Pin<Box<dyn Future<Output = Result<Self::Connection, Self::Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Create a single connection to the given database This is useful for cases where a full pool is not needed

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§