Skip to main content

ConnectionTrait

Trait ConnectionTrait 

Source
pub trait ConnectionTrait {
    // Required methods
    fn get_database_backend(&self) -> DbBackend;
    fn execute_raw(&self, stmt: Statement) -> Result<ExecResult, DbErr>;
    fn execute_unprepared(&self, sql: &str) -> Result<ExecResult, DbErr>;
    fn query_one_raw(
        &self,
        stmt: Statement,
    ) -> Result<Option<QueryResult>, DbErr>;
    fn query_all_raw(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr>;

    // Provided methods
    fn execute<S: StatementBuilder>(
        &self,
        stmt: &S,
    ) -> Result<ExecResult, DbErr> { ... }
    fn query_one<S: StatementBuilder>(
        &self,
        stmt: &S,
    ) -> Result<Option<QueryResult>, DbErr> { ... }
    fn query_all<S: StatementBuilder>(
        &self,
        stmt: &S,
    ) -> Result<Vec<QueryResult>, DbErr> { ... }
    fn support_returning(&self) -> bool { ... }
    fn is_mock_connection(&self) -> bool { ... }
}
Expand description

The generic API for a database connection that can perform query or execute statements. It abstracts database connection and transaction

Required Methods§

Source

fn get_database_backend(&self) -> DbBackend

Get the database backend for the connection. This depends on feature flags enabled.

Source

fn execute_raw(&self, stmt: Statement) -> Result<ExecResult, DbErr>

Execute a Statement

Source

fn execute_unprepared(&self, sql: &str) -> Result<ExecResult, DbErr>

Execute a unprepared Statement

Source

fn query_one_raw(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr>

Execute a Statement and return a single row of QueryResult

Source

fn query_all_raw(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr>

Execute a Statement and return a vector of QueryResult

Provided Methods§

Source

fn execute<S: StatementBuilder>(&self, stmt: &S) -> Result<ExecResult, DbErr>

Execute a [QueryStatement]

Source

fn query_one<S: StatementBuilder>( &self, stmt: &S, ) -> Result<Option<QueryResult>, DbErr>

Execute a [QueryStatement] and return a single row of QueryResult

Source

fn query_all<S: StatementBuilder>( &self, stmt: &S, ) -> Result<Vec<QueryResult>, DbErr>

Execute a [QueryStatement] and return a vector of QueryResult

Source

fn support_returning(&self) -> bool

Check if the connection supports RETURNING syntax on insert and update

Source

fn is_mock_connection(&self) -> bool

Check if the connection is a test connection for the Mock database

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§