pub trait PgRangeExpressionMethods: Expression + Sized {
    // Provided methods
    fn contains<T>(self, other: T) -> RangeContains<Self, T>
       where Self::SqlType: RangeHelper,
             <Self::SqlType as RangeHelper>::Inner: SqlType + TypedExpressionType,
             T: AsExpression<<Self::SqlType as RangeHelper>::Inner> { ... }
    fn contains_range<T>(self, other: T) -> ContainsRange<Self, T>
       where Self::SqlType: SqlType,
             T: AsExpression<Self::SqlType> { ... }
    fn is_contained_by<T>(self, other: T) -> IsContainedBy<Self, T>
       where Self::SqlType: SqlType,
             T: AsExpression<Self::SqlType> { ... }
    fn overlaps_with<T>(self, other: T) -> OverlapsWith<Self, T>
       where Self::SqlType: SqlType,
             T: AsExpression<Self::SqlType> { ... }
}
Available on crate feature postgres_backend only.
Expand description

PostgreSQL specific methods present on range expressions.

Provided Methods§

source

fn contains<T>(self, other: T) -> RangeContains<Self, T>
where Self::SqlType: RangeHelper, <Self::SqlType as RangeHelper>::Inner: SqlType + TypedExpressionType, T: AsExpression<<Self::SqlType as RangeHelper>::Inner>,

Creates a PostgreSQL @> expression.

This operator returns whether a range contains an specific element

§Example
diesel::insert_into(posts)
    .values(versions.eq((Bound::Included(5), Bound::Unbounded)))
    .execute(conn)?;

let cool_posts = posts.select(id)
    .filter(versions.contains(42))
    .load::<i32>(conn)?;
assert_eq!(vec![1], cool_posts);

let amazing_posts = posts.select(id)
    .filter(versions.contains(1))
    .load::<i32>(conn)?;
assert!(amazing_posts.is_empty());
source

fn contains_range<T>(self, other: T) -> ContainsRange<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

Creates a PostgreSQL @> expression.

This operator returns whether a range contains an specific element

§Example
diesel::insert_into(posts)
    .values(versions.eq((Bound::Included(5), Bound::Unbounded)))
    .execute(conn)?;

let cool_posts = posts.select(id)
    .filter(versions.contains_range((Bound::Included(10), Bound::Included(50))))
    .load::<i32>(conn)?;
assert_eq!(vec![1], cool_posts);

let amazing_posts = posts.select(id)
    .filter(versions.contains_range((Bound::Included(2), Bound::Included(7))))
    .load::<i32>(conn)?;
assert!(amazing_posts.is_empty());
source

fn is_contained_by<T>(self, other: T) -> IsContainedBy<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

Creates a PostgreSQL <@ expression.

This operator returns whether a range is contained by a specific element

§Example
diesel::insert_into(posts)
    .values(versions.eq((Bound::Included(5), Bound::Unbounded)))
    .execute(conn)?;

let cool_posts = posts.select(id)
    .filter(versions.is_contained_by((Bound::Included(1), Bound::Unbounded)))
    .load::<i32>(conn)?;
assert_eq!(vec![1], cool_posts);

let amazing_posts = posts.select(id)
    .filter(versions.is_contained_by((Bound::Included(1), Bound::Included(2))))
    .load::<i32>(conn)?;
assert!(amazing_posts.is_empty());
source

fn overlaps_with<T>(self, other: T) -> OverlapsWith<Self, T>
where Self::SqlType: SqlType, T: AsExpression<Self::SqlType>,

Creates a PostgreSQL && expression.

This operator returns whether two ranges overlap.

§Example
diesel::insert_into(posts)
    .values(&vec![
        (versions.eq((Bound::Included(1), Bound::Included(2)))),
        (versions.eq((Bound::Included(3), Bound::Included(4)))),
        (versions.eq((Bound::Included(5), Bound::Included(6))))
    ])
    .execute(conn)?;

let data = posts.select(id)
    .filter(versions.overlaps_with((Bound::Included(1), Bound::Included(4))))
    .load::<i32>(conn)?;
assert_eq!(vec![1, 2], data);

let data = posts.select(id)
    .filter(versions.overlaps_with((Bound::Included(7), Bound::Included(8))))
    .load::<i32>(conn)?;
assert!(data.is_empty());

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> PgRangeExpressionMethods for T
where T: Expression, T::SqlType: RangeOrNullableRange,