Trait diesel::expression::AsExpression [−][src]
pub trait AsExpression<T> {
type Expression: Expression<SqlType = T>;
fn as_expression(self) -> Self::Expression;
}Expand description
Converts a type to its representation for use in Diesel’s query builder.
This trait is used directly. Apps should typically use IntoSql instead.
Implementations of this trait will generally do one of 3 things:
-
Return
selffor types which are already parts of Diesel’s query builder -
Perform some implicit coercion (for example, allowing
nowto be used as bothTimestampandTimestamptz. -
Indicate that the type has data which will be sent separately from the query. This is generally referred as a “bind parameter”. Types which implement
ToSqlwill generally implementAsExpressionthis way.
Deriving
This trait can be automatically derived for any type which implements ToSql.
The type must be annotated with #[sql_type = "SomeType"].
If that annotation appears multiple times,
implementations will be generated for each one of them.
This will generate the following impls:
impl AsExpression<SqlType> for YourTypeimpl AsExpression<Nullable<SqlType>> for YourTypeimpl AsExpression<SqlType> for &'a YourTypeimpl AsExpression<Nullable<SqlType>> for &'a YourTypeimpl AsExpression<SqlType> for &'a &'b YourTypeimpl AsExpression<Nullable<SqlType>> for &'a &'b YourType
If your type is unsized,
you can specify this by adding the annotation #[diesel(not_sized)].
This will skip the impls for non-reference types.
Associated Types
type Expression: Expression<SqlType = T>
type Expression: Expression<SqlType = T>
The expression being returned
Required methods
fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
Perform the conversion