Trait diesel::pg::expression::expression_methods::ArrayExpressionMethods postgres
[−]
[src]
pub trait ArrayExpressionMethods<ST>: Expression<SqlType = Array<ST>> + Sized { fn overlaps_with<T>(self, other: T) -> OverlapsWith<Self, T::Expression>
where
T: AsExpression<Self::SqlType>, { ... } fn contains<T>(self, other: T) -> Contains<Self, T::Expression>
where
T: AsExpression<Self::SqlType>, { ... } fn is_contained_by<T>(self, other: T) -> IsContainedBy<Self, T::Expression>
where
T: AsExpression<Self::SqlType>, { ... } }
Provided Methods
fn overlaps_with<T>(self, other: T) -> OverlapsWith<Self, T::Expression> where
T: AsExpression<Self::SqlType>,
T: AsExpression<Self::SqlType>,
Compares two arrays for common elements, using the &&
operator in
the final SQL
Example
diesel::insert(&vec![ NewPost { tags: vec!["cool", "awesome"] }, NewPost { tags: vec!["awesome", "great"] }, NewPost { tags: vec!["cool", "great"] }, ]).into(posts).execute(&conn).unwrap(); let query = posts.select(id).filter(tags.overlaps_with(vec!["horrid", "cool"])); assert_eq!(Ok(vec![1, 3]), query.load(&conn)); let query = posts.select(id).filter(tags.overlaps_with(vec!["cool", "great"])); assert_eq!(Ok(vec![1, 2, 3]), query.load(&conn)); let query = posts.select(id).filter(tags.overlaps_with(vec!["horrid"])); assert_eq!(Ok(Vec::new()), query.load::<i32>(&conn));
fn contains<T>(self, other: T) -> Contains<Self, T::Expression> where
T: AsExpression<Self::SqlType>,
T: AsExpression<Self::SqlType>,
Compares whether an array contains another array, using the @>
operator.
Example
diesel::insert(&vec![ NewPost { tags: vec!["cool", "awesome"] }, ]).into(posts).execute(&conn).unwrap(); let query = posts.select(id).filter(tags.contains(vec!["cool"])); assert_eq!(Ok(vec![1]), query.load(&conn)); let query = posts.select(id).filter(tags.contains(vec!["cool", "amazing"])); assert_eq!(Ok(Vec::new()), query.load::<i32>(&conn));
fn is_contained_by<T>(self, other: T) -> IsContainedBy<Self, T::Expression> where
T: AsExpression<Self::SqlType>,
T: AsExpression<Self::SqlType>,
Compares whether an array is contained by another array, using the <@
operator.
This is the opposite of contains
Example
diesel::insert(&vec![ NewPost { tags: vec!["cool", "awesome"] }, ]).into(posts).execute(&conn).unwrap(); let query = posts.select(id).filter(tags.is_contained_by(vec!["cool", "awesome", "amazing"])); assert_eq!(Ok(vec![1]), query.load(&conn)); let query = posts.select(id).filter(tags.is_contained_by(vec!["cool"])); assert_eq!(Ok(Vec::new()), query.load::<i32>(&conn));
Implementors
impl<T, ST> ArrayExpressionMethods<ST> for T where
T: Expression<SqlType = Array<ST>>,postgres