pub trait Connection: Send + Syncwhere
for<'c> &'c mut <Self::DB as Database>::Connection: Executor<'c, Database = Self::DB>,
usize: ColumnIndex<<Self::DB as Database>::Row>,
<Self::DB as Database>::Row: RowExt,
<Self::DB as Database>::QueryResult: QueryResult,{
type DB: Database;
// Required methods
async fn pool(
&self,
target: Option<&str>,
) -> Result<Pool<Self::DB>, SqlError>;
fn query_timeout(&self) -> Option<u64>;
// Provided methods
async fn execute(
&self,
query: &str,
database: Option<&str>,
) -> Result<u64, SqlError> { ... }
async fn fetch_json(
&self,
query: &str,
database: Option<&str>,
) -> Result<Vec<Value>, SqlError> { ... }
async fn fetch_optional<T>(
&self,
query: &str,
database: Option<&str>,
) -> Result<Option<T>, SqlError>
where T: for<'r> Decode<'r, Self::DB> + Type<Self::DB> + Send + Unpin { ... }
async fn fetch_scalar<T>(
&self,
query: &str,
database: Option<&str>,
) -> Result<Vec<T>, SqlError>
where T: for<'r> Decode<'r, Self::DB> + Type<Self::DB> + Send + Unpin { ... }
}Expand description
Unified query surface every backend tool handler uses.
Backends supply three required items — DB,
pool, and query_timeout
— and receive default implementations for query execution.
§Errors
Query methods may return:
SqlError::InvalidIdentifier—databasefailed identifier validation.- [
SqlError::Connection] — the underlying driver failed. SqlError::QueryTimeout— the query exceeded the configured timeout.
Required Associated Types§
Required Methods§
Sourceasync fn pool(&self, target: Option<&str>) -> Result<Pool<Self::DB>, SqlError>
async fn pool(&self, target: Option<&str>) -> Result<Pool<Self::DB>, SqlError>
Resolves the connection pool for the given target database.
§Errors
SqlError::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 fetch_json(
&self,
query: &str,
database: Option<&str>,
) -> Result<Vec<Value>, SqlError>
async fn fetch_json( &self, query: &str, database: Option<&str>, ) -> Result<Vec<Value>, SqlError>
Sourceasync fn fetch_optional<T>(
&self,
query: &str,
database: Option<&str>,
) -> Result<Option<T>, SqlError>
async fn fetch_optional<T>( &self, query: &str, database: Option<&str>, ) -> Result<Option<T>, SqlError>
Runs a query and extracts column 0 from the first row, if any.
Returns None for both “no row returned” and “row where column 0
is NULL” (decode errors are caught, not propagated).
§Errors
See trait-level documentation.
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.