Trait diesel::prelude::IntoSql

source ·
pub trait IntoSql {
    // Provided methods
    fn into_sql<T>(self) -> AsExprOf<Self, T>
       where Self: AsExpression<T> + Sized,
             T: SqlType + TypedExpressionType { ... }
    fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>
       where &'a Self: AsExpression<T>,
             T: SqlType + TypedExpressionType { ... }
}
Expand description

Converts a type to its representation for use in Diesel’s query builder.

This trait only exists to make usage of AsExpression more ergonomic when the SqlType cannot be inferred. It is generally used when you need to use a Rust value as the left hand side of an expression, or when you want to select a constant value.

Example

use diesel::sql_types::Text;
let names = users::table
    .select("The Amazing ".into_sql::<Text>().concat(users::name))
    .load(conn);
let expected_names = vec![
    "The Amazing Sean".to_string(),
    "The Amazing Tess".to_string(),
];
assert_eq!(Ok(expected_names), names);

Provided Methods§

source

fn into_sql<T>(self) -> AsExprOf<Self, T>where Self: AsExpression<T> + Sized, T: SqlType + TypedExpressionType,

Convert self to an expression for Diesel’s query builder.

There is no difference in behavior between x.into_sql::<Y>() and AsExpression::<Y>::as_expression(x).

source

fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder.

There is no difference in behavior between x.as_sql::<Y>() and AsExpression::<Y>::as_expression(&x).

Implementors§

source§

impl<T> IntoSql for T