Skip to content

Commit

Permalink
range_adjacent
Browse files Browse the repository at this point in the history
  • Loading branch information
guissalustiano committed Oct 8, 2024
1 parent 5982953 commit 072faa4
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions diesel/src/pg/expression/expression_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,35 +1462,26 @@ pub trait PgRangeExpressionMethods: Expression + Sized {
/// ```rust
/// # include!("../../doctest_setup.rs");
/// #
/// # table! {
/// # posts {
/// # id -> Integer,
/// # versions -> Range<Integer>,
/// # }
/// # }
/// #
/// # fn main() {
/// # run_test().unwrap();
/// # }
/// #
/// # fn run_test() -> QueryResult<()> {
/// # use self::posts::dsl::*;
/// # use std::collections::Bound;
/// # use diesel::sql_types::{Integer, Range, Multirange};
/// # let conn = &mut establish_connection();
/// # diesel::sql_query("DROP TABLE IF EXISTS posts").execute(conn).unwrap();
/// # diesel::sql_query("CREATE TABLE posts (id SERIAL PRIMARY KEY, versions INT4RANGE NOT NULL)").execute(conn).unwrap();
/// #
/// diesel::insert_into(posts)
/// .values(&vec![
/// (versions.eq((Bound::Included(1), Bound::Excluded(2)))),
/// (versions.eq((Bound::Included(4), Bound::Excluded(7))))
/// ])
/// .execute(conn)?;
/// assert!(diesel::select(
/// (1..2).into_sql::<Range<Integer>>().range_adjacent(2..=6)
/// ).first::<bool>(conn).unwrap());
/// assert!(!diesel::select(
/// (4..7).into_sql::<Range<Integer>>().range_adjacent(2..=6)
/// ).first::<bool>(conn).unwrap());
///
/// let data = posts.select(versions.range_adjacent((Bound::Included(2),Bound::Included(6))))
/// .load::<bool>(conn)?;
/// let expected = vec![true, false];
/// assert_eq!(expected, data);
/// assert!(diesel::select(
/// vec![1..2].into_sql::<Multirange<Integer>>().range_adjacent(vec![2..=6])
/// ).first::<bool>(conn).unwrap());
/// assert!(!diesel::select(
/// vec![4..7].into_sql::<Multirange<Integer>>().range_adjacent(vec![2..=6])
/// ).first::<bool>(conn).unwrap());
/// # Ok(())
/// # }
/// ```
Expand Down

0 comments on commit 072faa4

Please sign in to comment.