diesel/expression/functions/aggregate_ordering.rs
1use sql_types::{IntoNullable, SqlOrd};
2
3sql_function! {
4 /// Represents a SQL `MAX` function. This function can only take types which are
5 /// ordered.
6 ///
7 /// # Examples
8 ///
9 /// ```rust
10 /// # #[macro_use] extern crate diesel;
11 /// # include!("../../doctest_setup.rs");
12 /// # use diesel::dsl::*;
13 /// #
14 /// # fn main() {
15 /// # use schema::animals::dsl::*;
16 /// # let connection = establish_connection();
17 /// assert_eq!(Ok(Some(8)), animals.select(max(legs)).first(&connection));
18 /// # }
19 #[aggregate]
20 fn max<ST: SqlOrd + IntoNullable>(expr: ST) -> ST::Nullable;
21}
22
23sql_function! {
24 /// Represents a SQL `MIN` function. This function can only take types which are
25 /// ordered.
26 ///
27 /// # Examples
28 ///
29 /// ```rust
30 /// # #[macro_use] extern crate diesel;
31 /// # include!("../../doctest_setup.rs");
32 /// # use diesel::dsl::*;
33 /// #
34 /// # fn main() {
35 /// # use schema::animals::dsl::*;
36 /// # let connection = establish_connection();
37 /// assert_eq!(Ok(Some(4)), animals.select(min(legs)).first(&connection));
38 /// # }
39 #[aggregate]
40 fn min<ST: SqlOrd + IntoNullable>(expr: ST) -> ST::Nullable;
41}