| 1 |
use crate::expression::grouped::Grouped; |
| 2 |
use crate::expression::Expression; |
| 3 |
use crate::helper_types; |
| 4 |
use crate::sql_types::BoolOrNullableBool; |
| 5 |
|
| 6 |
/// Creates a SQL `NOT` expression |
| 7 |
/// |
| 8 |
/// # Example |
| 9 |
/// |
| 10 |
/// ```rust |
| 11 |
/// # include!("../doctest_setup.rs"); |
| 12 |
/// # |
| 13 |
/// # fn main() { |
| 14 |
/// # use schema::users::dsl::*; |
| 15 |
/// # let connection = &mut establish_connection(); |
| 16 |
/// use diesel::dsl::not; |
| 17 |
/// |
| 18 |
/// let users_with_name = users.select(id).filter(name.eq("Sean")); |
| 19 |
/// let users_not_with_name = users.select(id).filter(not(name.eq("Sean"))); |
| 20 |
/// |
| 21 |
/// assert_eq!(Ok(1), users_with_name.first(connection)); |
| 22 |
/// assert_eq!(Ok(2), users_not_with_name.first(connection)); |
| 23 |
/// # } |
| 24 |
/// ``` |
| 25 |
pub fn not<T>(expr: T) -> helper_types::not<T> |
| 26 |
where |
| 27 |
T: Expression, |
| 28 |
<T as Expression>::SqlType: BoolOrNullableBool, |
| 29 |
{ |
| 30 |
super::operators::Not::new(Grouped(expr)) |
| 31 |
} |