Trait diesel::expression::AsExpression
[−]
[src]
pub trait AsExpression<T> { type Expression: Expression<SqlType = T>; fn as_expression(self) -> Self::Expression; }
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
self
for types which are already parts of Diesel's query builder - Perform some implicit coercion (for example, allowing
now
to be used as bothTimestamp
andTimestamptz
. - 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
ToSql
will generally implementAsExpression
this 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 YourType
impl AsExpression<Nullable<SqlType>> for YourType
impl AsExpression<SqlType> for &'a YourType
impl AsExpression<Nullable<SqlType>> for &'a YourType
impl AsExpression<SqlType> for &'a &'b YourType
impl 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>
The expression being returned
Required Methods
fn as_expression(self) -> Self::Expression
Perform the conversion
Implementations on Foreign Types
impl<'a, 'b, ST, T> AsExpression<Array<ST>> for &'a [T]
[src]
type Expression = Bound<Array<ST>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, 'b, ST, T> AsExpression<Nullable<Array<ST>>> for &'a [T]
[src]
type Expression = Bound<Nullable<Array<ST>>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, 'b, ST, T> AsExpression<Array<ST>> for Vec<T>
[src]
type Expression = Bound<Array<ST>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, 'b, ST, T> AsExpression<Nullable<Array<ST>>> for Vec<T>
[src]
type Expression = Bound<Nullable<Array<ST>>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, 'b, ST, T> AsExpression<Array<ST>> for &'a Vec<T>
[src]
type Expression = Bound<Array<ST>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, 'b, ST, T> AsExpression<Nullable<Array<ST>>> for &'a Vec<T>
[src]
type Expression = Bound<Nullable<Array<ST>>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<ST, T> AsExpression<Range<ST>> for (Bound<T>, Bound<T>)
[src]
type Expression = SqlBound<Range<ST>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<ST, T> AsExpression<Nullable<Range<ST>>> for (Bound<T>, Bound<T>)
[src]
type Expression = SqlBound<Nullable<Range<ST>>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<T, ST> AsExpression<Nullable<ST>> for Option<T> where
ST: NotNull,
[src]
ST: NotNull,
type Expression = Bound<Nullable<ST>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, T, ST> AsExpression<Nullable<ST>> for &'a Option<T> where
ST: NotNull,
[src]
ST: NotNull,
type Expression = Bound<Nullable<ST>, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, T: ?Sized, ST> AsExpression<ST> for Cow<'a, T> where
T: 'a + ToOwned,
Bound<ST, Cow<'a, T>>: Expression<SqlType = ST>,
[src]
T: 'a + ToOwned,
Bound<ST, Cow<'a, T>>: Expression<SqlType = ST>,
type Expression = Bound<ST, Self>
fn as_expression(self) -> Self::Expression
[src]
impl<'a, 'b, T: ?Sized, ST> AsExpression<ST> for &'b Cow<'a, T> where
T: 'a + ToOwned,
Bound<ST, &'b T>: Expression<SqlType = ST>,
[src]
T: 'a + ToOwned,
Bound<ST, &'b T>: Expression<SqlType = ST>,
type Expression = Bound<ST, &'b T>
fn as_expression(self) -> Self::Expression
[src]
Implementors
impl AsExpression<Timestamptz> for now type Expression = Coerce<now, Timestamptz>;
impl AsExpression<Nullable<Timestamptz>> for now type Expression = Coerce<now, Nullable<Timestamptz>>;
impl<T: Expression> AsExpression<T::SqlType> for T type Expression = Self;