From 072faa42001ae2de46530a6228fc2857049059bc Mon Sep 17 00:00:00 2001 From: Guilherme Stabach Salustiano Date: Mon, 7 Oct 2024 23:53:20 -0300 Subject: [PATCH] range_adjacent --- .../src/pg/expression/expression_methods.rs | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/diesel/src/pg/expression/expression_methods.rs b/diesel/src/pg/expression/expression_methods.rs index 53594d9168bc..42dc34b87c1f 100644 --- a/diesel/src/pg/expression/expression_methods.rs +++ b/diesel/src/pg/expression/expression_methods.rs @@ -1462,35 +1462,26 @@ pub trait PgRangeExpressionMethods: Expression + Sized { /// ```rust /// # include!("../../doctest_setup.rs"); /// # - /// # table! { - /// # posts { - /// # id -> Integer, - /// # versions -> Range, - /// # } - /// # } - /// # /// # 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_adjacent(2..=6) + /// ).first::(conn).unwrap()); + /// assert!(!diesel::select( + /// (4..7).into_sql::>().range_adjacent(2..=6) + /// ).first::(conn).unwrap()); /// - /// let data = posts.select(versions.range_adjacent((Bound::Included(2),Bound::Included(6)))) - /// .load::(conn)?; - /// let expected = vec![true, false]; - /// assert_eq!(expected, data); + /// assert!(diesel::select( + /// vec![1..2].into_sql::>().range_adjacent(vec![2..=6]) + /// ).first::(conn).unwrap()); + /// assert!(!diesel::select( + /// vec![4..7].into_sql::>().range_adjacent(vec![2..=6]) + /// ).first::(conn).unwrap()); /// # Ok(()) /// # } /// ```