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>>;
// Provided method
fn refresh_materialized_view(
&self,
view_name: &str,
concurrently: bool,
) -> BoxFuture<'_, QueryResult<()>> { ... }
}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§
Sourcefn query_many<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<T>>>
fn query_many<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<Vec<T>>>
Execute a SELECT query and return rows.
Sourcefn query_one<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<T>>
fn query_one<T: Model + Send + 'static>( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<T>>
Execute a SELECT query expecting one result.
Sourcefn query_optional<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Option<T>>>
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.
Sourcefn execute_insert<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<T>>
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.
Sourcefn execute_update<T: Model + Send + 'static>(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<Vec<T>>>
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.
Sourcefn execute_delete(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn execute_delete( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Execute a DELETE query and return affected rows count.
Sourcefn execute_raw(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn execute_raw( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Execute a raw SQL query.
Sourcefn count(
&self,
sql: &str,
params: Vec<FilterValue>,
) -> BoxFuture<'_, QueryResult<u64>>
fn count( &self, sql: &str, params: Vec<FilterValue>, ) -> BoxFuture<'_, QueryResult<u64>>
Get a count of records.
Provided Methods§
Sourcefn refresh_materialized_view(
&self,
view_name: &str,
concurrently: bool,
) -> BoxFuture<'_, QueryResult<()>>
fn refresh_materialized_view( &self, view_name: &str, concurrently: bool, ) -> BoxFuture<'_, QueryResult<()>>
Refresh a materialized view.
For PostgreSQL, this executes REFRESH MATERIALIZED VIEW.
For MSSQL, this rebuilds the indexed view.
For databases that don’t support materialized views, this returns an error.
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.