pub trait Driver:
Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn url(&self) -> Cow<'_, str>;
fn capability(&self) -> &'static Capability;
fn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn generate_migration(&self, schema_diff: &SchemaDiff<'_>) -> Migration;
fn reset_db<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn max_connections(&self) -> Option<usize> { ... }
}Expand description
Factory for database connections and provider of driver-level metadata.
Each database backend (SQLite, PostgreSQL, MySQL, DynamoDB) implements this
trait to tell Toasty what the backend supports (Capability) and to
create Connection instances on demand.
§Examples
use toasty_core::driver::Driver;
// Drivers are typically constructed from a connection URL:
let driver: Box<dyn Driver> = make_driver("sqlite::memory:").await;
assert!(!driver.url().is_empty());
let capability = driver.capability();
assert!(capability.sql);
let conn = driver.connect().await.unwrap();Required Methods§
Sourcefn capability(&self) -> &'static Capability
fn capability(&self) -> &'static Capability
Describes the driver’s capability, which informs the query planner.
Sourcefn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Connection>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates a new connection to the database.
This method is called by the [Pool] whenever a Connection is requested while none is
available and there is room to create a new Connection.
Sourcefn generate_migration(&self, schema_diff: &SchemaDiff<'_>) -> Migration
fn generate_migration(&self, schema_diff: &SchemaDiff<'_>) -> Migration
Generates a migration from a SchemaDiff.
Sourcefn reset_db<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn reset_db<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Drops the entire database and recreates an empty one without applying migrations.
Used primarily in tests to start with a clean slate.
Provided Methods§
Sourcefn max_connections(&self) -> Option<usize>
fn max_connections(&self) -> Option<usize>
Returns the maximum number of simultaneous database connections supported. For example,
this is Some(1) for the in-memory SQLite driver which cannot be pooled.