From fa428913ef5bdb4d1e34902c60101ccea31e5f06 Mon Sep 17 00:00:00 2001 From: "Guilherme S. Salustiano" Date: Sat, 13 Jul 2024 14:11:09 +0200 Subject: [PATCH] lower_inf --- diesel/src/pg/expression/functions.rs | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/diesel/src/pg/expression/functions.rs b/diesel/src/pg/expression/functions.rs index 246233d81bde..28404250a179 100644 --- a/diesel/src/pg/expression/functions.rs +++ b/diesel/src/pg/expression/functions.rs @@ -275,6 +275,48 @@ define_sql_function! { fn upper_inc(range: T) -> Bool; } +define_sql_function! { + /// Returns if the range's lower bound inclusive. + /// # Example + /// + /// ```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; + /// # 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(); + /// # + /// use diesel::dsl::lower_inf; + /// diesel::insert_into(posts) + /// .values(&[ + /// versions.eq((Bound::Included(5), Bound::Excluded(7))), + /// versions.eq((Bound::Unbounded, Bound::Excluded(7))), + /// ]).execute(conn)?; + /// + /// let cool_posts = posts.select(lower_inf(versions)) + /// .load::(conn)?; + /// assert_eq!(vec![false, true], cool_posts); + /// # Ok(()) + /// # } + /// ``` + #[cfg(feature = "postgres_backend")] + fn lower_inf(range: T) -> Bool; +} + define_sql_function! { /// Returns range of integer. /// # Example