[][src]Trait diesel::expression_methods::BoolExpressionMethods

pub trait BoolExpressionMethods: Expression + Sized {
    fn and<T>(self, other: T) -> And<Self, T>
    where
        Self::SqlType: SqlType + IntoNullable,
        <Self::SqlType as IntoNullable>::Nullable: SingleValue,
        T: AsExpression<<Self::SqlType as IntoNullable>::Nullable>,
        And<Self, T::Expression>: Expression
, { ... }
fn or<T>(self, other: T) -> Or<Self, T>
    where
        Self::SqlType: SqlType + IntoNullable,
        <Self::SqlType as IntoNullable>::Nullable: SingleValue,
        T: AsExpression<<Self::SqlType as IntoNullable>::Nullable>,
        Or<Self, T::Expression>: Expression
, { ... } }

Methods present on boolean expressions

Provided methods

fn and<T>(self, other: T) -> And<Self, T> where
    Self::SqlType: SqlType + IntoNullable,
    <Self::SqlType as IntoNullable>::Nullable: SingleValue,
    T: AsExpression<<Self::SqlType as IntoNullable>::Nullable>,
    And<Self, T::Expression>: Expression

Creates a SQL AND expression

Example

diesel::insert_into(animals)
    .values(&vec![
        (species.eq("ferret"), legs.eq(4), name.eq("Freddy")),
        (species.eq("ferret"), legs.eq(4), name.eq("Jack")),
    ])
    .execute(&connection)?;

let data = animals.select((species, name))
    .filter(species.eq("ferret").and(name.eq("Jack")))
    .load(&connection)?;
let expected = vec![
    (String::from("ferret"), Some(String::from("Jack"))),
];
assert_eq!(expected, data);

fn or<T>(self, other: T) -> Or<Self, T> where
    Self::SqlType: SqlType + IntoNullable,
    <Self::SqlType as IntoNullable>::Nullable: SingleValue,
    T: AsExpression<<Self::SqlType as IntoNullable>::Nullable>,
    Or<Self, T::Expression>: Expression

Creates a SQL OR expression

The result will be wrapped in parenthesis, so that precedence matches that of your function calls. For example, false.and(false.or(true)) will generate the SQL FALSE AND (FALSE OR TRUE), which returns false

Example

diesel::insert_into(animals)
    .values(&vec![
        (species.eq("ferret"), legs.eq(4), name.eq("Freddy")),
        (species.eq("ferret"), legs.eq(4), name.eq("Jack")),
    ])
    .execute(&connection)?;

let data = animals.select((species, name))
    .filter(species.eq("ferret").or(name.eq("Jack")))
    .load(&connection)?;
let expected = vec![
    (String::from("dog"), Some(String::from("Jack"))),
    (String::from("ferret"), Some(String::from("Freddy"))),
    (String::from("ferret"), Some(String::from("Jack"))),
];
assert_eq!(expected, data);
Loading content...

Implementors

impl<T> BoolExpressionMethods for T where
    T: Expression,
    T::SqlType: BoolOrNullableBool
[src]

Loading content...