From c40d681380abd2e6cd82897b8c5c88ef292aa4e5 Mon Sep 17 00:00:00 2001 From: Guilherme Stabach Salustiano Date: Tue, 8 Oct 2024 00:04:36 -0300 Subject: [PATCH] union_range --- .../src/pg/expression/expression_methods.rs | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/diesel/src/pg/expression/expression_methods.rs b/diesel/src/pg/expression/expression_methods.rs index 42dc34b87c1f..da9527c1f2b3 100644 --- a/diesel/src/pg/expression/expression_methods.rs +++ b/diesel/src/pg/expression/expression_methods.rs @@ -1520,34 +1520,20 @@ 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::Included(2)))) - /// ]) - /// .execute(conn)?; + /// assert!(diesel::select( + /// (1..=2).into_sql::>().union_range(2..=6).eq(1..=6) + /// ).first::(conn).unwrap()); /// - /// let data = posts.select(versions.union_range((Bound::Included(2),Bound::Included(6)))) - /// .load::<(Bound,Bound)>(conn)?; - /// let expected_range = (Bound::Included(1),Bound::Excluded(7)); - /// assert_eq!(expected_range, data[0]); + /// assert!(diesel::select( + /// vec![1..=2].into_sql::>().union_range(vec![1..=6]).eq(vec![1..=6]) + /// ).first::(conn).unwrap()); /// # Ok(()) /// # } /// ```