Trait diesel::expression::BoxableExpression [−][src]
pub trait BoxableExpression<QS, DB> where
DB: Backend,
Self: Expression,
Self: SelectableExpression<QS>,
Self: NonAggregate,
Self: QueryFragment<DB>, { }
Helper trait used when boxing expressions.
In Rust you cannot create a trait object with more than one trait.
This type has all of the additional traits you would want when using
Box<Expression>
as a single trait object.
This is typically used as the return type of a function. For cases where you want to dynamically construct a query, boxing the query is usually more ergonomic.
Examples
use diesel::sql_types::Bool; enum Search { Id(i32), Name(String), } type DB = diesel::sqlite::Sqlite; fn find_user(search: Search) -> Box<BoxableExpression<users::table, DB, SqlType = Bool>> { match search { Search::Id(id) => Box::new(users::id.eq(id)), Search::Name(name) => Box::new(users::name.eq(name)), } } let user_one = users::table .filter(find_user(Search::Id(1))) .first(&conn)?; assert_eq!((1, String::from("Sean")), user_one); let tess = users::table .filter(find_user(Search::Name("Tess".into()))) .first(&conn)?; assert_eq!((2, String::from("Tess")), tess);
Trait Implementations
impl<'a, QS, ST, DB> QueryId for BoxableExpression<QS, DB, SqlType = ST> + 'a
[src]
impl<'a, QS, ST, DB> QueryId for BoxableExpression<QS, DB, SqlType = ST> + 'a
type QueryId = ()
A type which uniquely represents Self
in a SQL query. Read more
const HAS_STATIC_QUERY_ID: bool
HAS_STATIC_QUERY_ID: bool = false
Can the SQL generated by Self
be uniquely identified by its type? Read more
fn query_id() -> Option<TypeId>
[src]
fn query_id() -> Option<TypeId>
Returns the type id of Self::QueryId
if Self::HAS_STATIC_QUERY_ID
. Returns None
otherwise. Read more
Implementors
impl<QS, T, DB> BoxableExpression<QS, DB> for T where
DB: Backend,
T: Expression,
T: SelectableExpression<QS>,
T: NonAggregate,
T: QueryFragment<DB>,