From 59829538cd6bd82c18fb14010c25d2e4acf04573 Mon Sep 17 00:00:00 2001 From: Guilherme Stabach Salustiano Date: Mon, 7 Oct 2024 23:34:29 -0300 Subject: [PATCH] range_extends_left_to --- .../src/pg/expression/expression_methods.rs | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/diesel/src/pg/expression/expression_methods.rs b/diesel/src/pg/expression/expression_methods.rs index 38c53ca65056..53594d9168bc 100644 --- a/diesel/src/pg/expression/expression_methods.rs +++ b/diesel/src/pg/expression/expression_methods.rs @@ -1206,39 +1206,33 @@ 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(versions.eq((Bound::Included(1), Bound::Excluded(20)))) - /// .execute(conn)?; - /// - /// let cool_posts = posts.select(versions.range_extends_left_to((Bound::Included(-10), Bound::Excluded(5)))) - /// .get_result::(conn)?; - /// assert_eq!(true, cool_posts); - /// - /// let cool_posts = posts.select(versions.range_extends_left_to((Bound::Included(-10), Bound::Excluded(-5)))) - /// .get_result::(conn)?; - /// assert_eq!(true, cool_posts); + /// assert!(diesel::select( + /// (1..20).into_sql::>().range_extends_left_to(-10..5) + /// ).first::(conn).unwrap()); + /// assert!(diesel::select( + /// (1..20).into_sql::>().range_extends_left_to(-10..-5) + /// ).first::(conn).unwrap()); + /// assert!(!diesel::select( + /// (1..20).into_sql::>().range_extends_left_to(25..30) + /// ).first::(conn).unwrap()); /// - /// let amazing_posts = posts.select(versions.range_extends_left_to((Bound::Included(25), Bound::Excluded(30)))) - /// .get_result::(conn)?; - /// assert_eq!(false, amazing_posts); + /// assert!(diesel::select( + /// vec![1..20].into_sql::>().range_extends_left_to(vec![-10..5]) + /// ).first::(conn).unwrap()); + /// assert!(diesel::select( + /// vec![1..20].into_sql::>().range_extends_left_to(vec![-10..-5]) + /// ).first::(conn).unwrap()); + /// assert!(!diesel::select( + /// vec![1..20].into_sql::>().range_extends_left_to(vec![25..30]) + /// ).first::(conn).unwrap()); /// # Ok(()) /// # } /// ```