Skip to content

Commit

Permalink
difference_range
Browse files Browse the repository at this point in the history
  • Loading branch information
guissalustiano committed Oct 8, 2024
1 parent c40d681 commit 7de39ed
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions diesel/src/pg/expression/expression_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,34 +1575,20 @@ 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::Included(8))))
/// ])
/// .execute(conn)?;
/// assert!(diesel::select(
/// (1..=8).into_sql::<Range<Integer>>().difference_range(3..=8).eq(1..3)
/// ).first::<bool>(conn).unwrap());
///
/// let data = posts.select(versions.difference_range((Bound::Included(3),Bound::Included(8))))
/// .load::<(Bound<i32>,Bound<i32>)>(conn)?;
/// let expected_range = (Bound::Included(1),Bound::Excluded(3));
/// assert_eq!(expected_range, data[0]);
/// assert!(diesel::select(
/// vec![1..=8].into_sql::<Multirange<Integer>>().difference_range(vec![3..=8]).eq(vec![1..3])
/// ).first::<bool>(conn).unwrap());
/// # Ok(())
/// # }
/// ```
Expand Down

0 comments on commit 7de39ed

Please sign in to comment.