pub trait DatabaseAdapter: Send + Sync {
Show 13 methods
// Required methods
fn name(&self) -> &str;
fn backend(&self) -> DatabaseBackend;
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<JsonValue>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<JsonValue>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn as_any(&self) -> &dyn Any;
fn clone_box(&self) -> Box<dyn DatabaseAdapter>;
// Provided methods
fn query(&self) -> QueryBuilder { ... }
fn type_backend(&self) -> DatabaseBackend { ... }
fn begin_transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn commit<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn rollback<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Unified database adapter trait
This trait provides a common interface for all database backends, enabling RustF to work with PostgreSQL, MySQL, and SQLite through the same API.
Required Methods§
Sourcefn backend(&self) -> DatabaseBackend
fn backend(&self) -> DatabaseBackend
Get the database backend type
Sourcefn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<QueryResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<JsonValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_all<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<Vec<JsonValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<JsonValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn fetch_one<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
params: Vec<SqlValue>,
) -> Pin<Box<dyn Future<Output = Result<Option<JsonValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn ping<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Test database connectivity
§Returns
Ok(true)- Database is connected and respondingErr(Error)- Connection test failed
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Get the underlying connection pool as Any for downcasting
This allows code that knows the specific database type to access the underlying sqlx pool directly when needed.
Sourcefn clone_box(&self) -> Box<dyn DatabaseAdapter>
fn clone_box(&self) -> Box<dyn DatabaseAdapter>
Clone the adapter into a boxed trait object
Provided Methods§
Sourcefn query(&self) -> QueryBuilder
fn query(&self) -> QueryBuilder
Create a new query builder for this database
§Returns
A QueryBuilder configured for this database’s SQL dialect
Sourcefn type_backend(&self) -> DatabaseBackend
fn type_backend(&self) -> DatabaseBackend
Get the database backend as the type system’s DatabaseBackend
Sourcefn begin_transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn begin_transaction<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Begin a transaction (optional, can return error for unsupported databases)
§Returns
Ok(())- Transaction startedErr(Error)- If transactions aren’t supported or fail to start
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".