pub trait Connection: Send + Sync {
type DB: Database;
const IDENTIFIER_QUOTE: char;
// Required methods
async fn pool(
&self,
target: Option<&str>,
) -> Result<Pool<Self::DB>, AppError>;
fn query_timeout(&self) -> Option<u64>;
// Provided methods
async fn execute(
&self,
query: &str,
database: Option<&str>,
) -> Result<u64, AppError>
where for<'c> &'c mut <Self::DB as Database>::Connection: Executor<'c, Database = Self::DB>,
<Self::DB as Database>::QueryResult: QueryResult { ... }
async fn fetch(
&self,
query: &str,
database: Option<&str>,
) -> Result<Vec<Value>, AppError>
where for<'c> &'c mut <Self::DB as Database>::Connection: Executor<'c, Database = Self::DB>,
<Self::DB as Database>::Row: RowExt { ... }
async fn fetch_optional(
&self,
query: &str,
database: Option<&str>,
) -> Result<Option<Value>, AppError>
where for<'c> &'c mut <Self::DB as Database>::Connection: Executor<'c, Database = Self::DB>,
<Self::DB as Database>::Row: RowExt { ... }
fn quote_identifier(&self, name: &str) -> String { ... }
fn quote_string(&self, value: &str) -> String { ... }
}Expand description
Unified query and quoting surface every backend tool handler uses.
Backends supply four required items — DB,
IDENTIFIER_QUOTE,
pool, and query_timeout
— and receive default implementations for query execution and SQL quoting.
§Errors
Query methods may return:
AppError::InvalidIdentifier—databasefailed identifier validation.AppError::Connection— the underlying driver failed.AppError::QueryTimeout— the query exceeded the configured timeout.
Required Associated Constants§
Sourceconst IDENTIFIER_QUOTE: char
const IDENTIFIER_QUOTE: char
Character used to quote identifiers (` for MySQL, " for PostgreSQL/SQLite).
Required Associated Types§
Required Methods§
Sourceasync fn pool(&self, target: Option<&str>) -> Result<Pool<Self::DB>, AppError>
async fn pool(&self, target: Option<&str>) -> Result<Pool<Self::DB>, AppError>
Resolves the connection pool for the given target database.
§Errors
AppError::InvalidIdentifier—targetfailed validation.
Sourcefn query_timeout(&self) -> Option<u64>
fn query_timeout(&self) -> Option<u64>
Returns the configured query timeout in seconds, if any.
Provided Methods§
Sourceasync fn execute(
&self,
query: &str,
database: Option<&str>,
) -> Result<u64, AppError>where
for<'c> &'c mut <Self::DB as Database>::Connection: Executor<'c, Database = Self::DB>,
<Self::DB as Database>::QueryResult: QueryResult,
async fn execute(
&self,
query: &str,
database: Option<&str>,
) -> Result<u64, AppError>where
for<'c> &'c mut <Self::DB as Database>::Connection: Executor<'c, Database = Self::DB>,
<Self::DB as Database>::QueryResult: QueryResult,
Sourceasync fn fetch_optional(
&self,
query: &str,
database: Option<&str>,
) -> Result<Option<Value>, AppError>
async fn fetch_optional( &self, query: &str, database: Option<&str>, ) -> Result<Option<Value>, AppError>
Sourcefn quote_identifier(&self, name: &str) -> String
fn quote_identifier(&self, name: &str) -> String
Wraps name in the backend’s identifier quote character.
Sourcefn quote_string(&self, value: &str) -> String
fn quote_string(&self, value: &str) -> String
Wraps value in single quotes for use as a SQL string literal.
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.