rocket_db_pools::diesel::prelude

Trait IntoSql

Source
pub trait IntoSql {
    // Provided methods
    fn into_sql<T>(self) -> Self::Expression
       where Self: Sized + AsExpression<T>,
             T: SqlType + TypedExpressionType { ... }
    fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
       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) -> Self::Expression

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) -> <&'a Self as AsExpression<T>>::Expression
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).

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.

Implementors§

Source§

impl<T> IntoSql for T