QueryEngine

Trait QueryEngine 

Source
pub trait QueryEngine:
    Send
    + Sync
    + Clone
    + 'static {
    // Required methods
    fn query_many<T: Model + Send + 'static>(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<Vec<T>>>;
    fn query_one<T: Model + Send + 'static>(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<T>>;
    fn query_optional<T: Model + Send + 'static>(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<Option<T>>>;
    fn execute_insert<T: Model + Send + 'static>(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<T>>;
    fn execute_update<T: Model + Send + 'static>(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<Vec<T>>>;
    fn execute_delete(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<u64>>;
    fn execute_raw(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<u64>>;
    fn count(
        &self,
        sql: &str,
        params: Vec<FilterValue>,
    ) -> BoxFuture<'_, QueryResult<u64>>;
}
Expand description

The query engine abstraction.

This trait defines how queries are executed against a database. Different implementations can be provided for different databases (PostgreSQL, MySQL, SQLite, etc.).

Required Methods§

Source

fn query_many<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>

Execute a SELECT query and return rows.

Source

fn query_one<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>

Execute a SELECT query expecting one result.

Source

fn query_optional<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Option<T>>>

Execute a SELECT query expecting zero or one result.

Source

fn execute_insert<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>

Execute an INSERT query and return the created row.

Source

fn execute_update<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>

Execute an UPDATE query and return affected rows.

Source

fn execute_delete( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>

Execute a DELETE query and return affected rows count.

Source

fn execute_raw( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>

Execute a raw SQL query.

Source

fn count( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>

Get a count of records.

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.

Implementors§