Skip to content

Commit 6ef23bd

Browse files
authored
Merge pull request #3783 from weiznich/fix/auto_type_defs
Fix most type-defs for `#[auto_type]` by cleaning up all the type defs
2 parents e5fc2a8 + 94d1a5e commit 6ef23bd

File tree

63 files changed

+1019
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1019
-441
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Increasing the minimal supported Rust version will always be coupled at least wi
2525
### Changed
2626

2727
* The minimal officially supported rustc version is now 1.70.0
28+
* Deprecated `sql_function!` in favour of `define_sql_function!` which provides compatibility with `#[dsl::auto_type]`
2829

2930
## [2.1.0] 2023-05-26
3031

diesel/src/expression/count.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22

3-
use super::functions::sql_function;
3+
use super::functions::define_sql_function;
44
use super::{is_aggregate, AsExpression};
55
use super::{Expression, ValidGrouping};
66
use crate::backend::Backend;
@@ -9,7 +9,7 @@ use crate::result::QueryResult;
99
use crate::sql_types::{BigInt, DieselNumericOps, SingleValue, SqlType};
1010
use crate::{AppearsOnTable, SelectableExpression};
1111

12-
sql_function! {
12+
define_sql_function! {
1313
/// Creates a SQL `COUNT` expression
1414
///
1515
/// As with most bare functions, this is not exported by default. You can import

diesel/src/expression/exists.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::backend::{sql_dialect, Backend, SqlDialect};
55
use crate::expression::subselect::Subselect;
66
use crate::expression::{AppearsOnTable, Expression, SelectableExpression, ValidGrouping};
7-
use crate::helper_types::exists;
7+
use crate::helper_types;
88
use crate::query_builder::*;
99
use crate::result::QueryResult;
1010
use crate::sql_types::Bool;
@@ -32,7 +32,7 @@ use crate::sql_types::Bool;
3232
/// assert_eq!(Ok(false), jim_exists);
3333
/// # }
3434
/// ```
35-
pub fn exists<T>(query: T) -> exists<T> {
35+
pub fn exists<T>(query: T) -> helper_types::exists<T> {
3636
Exists {
3737
subselect: Subselect::new(query),
3838
}

diesel/src/expression/functions/aggregate_folding.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::expression::functions::sql_function;
1+
use crate::expression::functions::define_sql_function;
22
use crate::sql_types::Foldable;
33

4-
sql_function! {
4+
define_sql_function! {
55
/// Represents a SQL `SUM` function. This function can only take types which are
66
/// Foldable.
77
///
@@ -21,7 +21,7 @@ sql_function! {
2121
fn sum<ST: Foldable>(expr: ST) -> ST::Sum;
2222
}
2323

24-
sql_function! {
24+
define_sql_function! {
2525
/// Represents a SQL `AVG` function. This function can only take types which are
2626
/// Foldable.
2727
///

diesel/src/expression/functions/aggregate_ordering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use self::private::SqlOrdAggregate;
2-
use crate::expression::functions::sql_function;
2+
use crate::expression::functions::define_sql_function;
33

4-
sql_function! {
4+
define_sql_function! {
55
/// Represents a SQL `MAX` function. This function can only take types which are
66
/// ordered.
77
///
@@ -20,7 +20,7 @@ sql_function! {
2020
fn max<ST: SqlOrdAggregate>(expr: ST) -> ST::Ret;
2121
}
2222

23-
sql_function! {
23+
define_sql_function! {
2424
/// Represents a SQL `MIN` function. This function can only take types which are
2525
/// ordered.
2626
///

diesel/src/expression/functions/date_and_time.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::backend::Backend;
22
use crate::expression::coerce::Coerce;
3-
use crate::expression::functions::sql_function;
3+
use crate::expression::functions::define_sql_function;
44
use crate::expression::{AsExpression, Expression, ValidGrouping};
55
use crate::query_builder::*;
66
use crate::result::QueryResult;
@@ -27,7 +27,7 @@ impl_selectable_expression!(now);
2727

2828
operator_allowed!(now, Add, add);
2929
operator_allowed!(now, Sub, sub);
30-
sql_function! {
30+
define_sql_function! {
3131
/// Represents the SQL `DATE` function. The argument should be a Timestamp
3232
/// expression, and the return value will be an expression of type Date.
3333
///

diesel/src/expression/functions/helper_types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ use crate::expression::operators;
88
pub type not<Expr> = operators::Not<Grouped<Expr>>;
99

1010
/// The return type of [`max(expr)`](crate::dsl::max())
11-
pub type max<Expr> = super::aggregate_ordering::max::HelperType<SqlTypeOf<Expr>, Expr>;
11+
pub type max<Expr> = super::aggregate_ordering::max<SqlTypeOf<Expr>, Expr>;
1212

1313
/// The return type of [`min(expr)`](crate::dsl::min())
14-
pub type min<Expr> = super::aggregate_ordering::min::HelperType<SqlTypeOf<Expr>, Expr>;
14+
pub type min<Expr> = super::aggregate_ordering::min<SqlTypeOf<Expr>, Expr>;
1515

1616
/// The return type of [`sum(expr)`](crate::dsl::sum())
17-
pub type sum<Expr> = super::aggregate_folding::sum::HelperType<SqlTypeOf<Expr>, Expr>;
17+
pub type sum<Expr> = super::aggregate_folding::sum<SqlTypeOf<Expr>, Expr>;
1818

1919
/// The return type of [`avg(expr)`](crate::dsl::avg())
20-
pub type avg<Expr> = super::aggregate_folding::avg::HelperType<SqlTypeOf<Expr>, Expr>;
20+
pub type avg<Expr> = super::aggregate_folding::avg<SqlTypeOf<Expr>, Expr>;
2121

2222
/// The return type of [`exists(expr)`](crate::dsl::exists())
2323
pub type exists<Expr> = crate::expression::exists::Exists<Expr>;

diesel/src/expression/functions/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//! Helper macros to define custom sql functions
22
33
#[doc(inline)]
4+
pub use diesel_derives::define_sql_function;
5+
6+
#[doc(inline)]
7+
#[cfg(all(feature = "with-deprecated", not(feature = "without-deprecated")))]
48
pub use diesel_derives::sql_function_proc as sql_function;
59

610
#[macro_export]
@@ -73,7 +77,7 @@ macro_rules! no_arg_sql_function_body {
7377
/// function.
7478
#[deprecated(
7579
since = "2.0.0",
76-
note = "Use `sql_function!` instead. See `CHANGELOG.md` for migration instructions"
80+
note = "Use `define_sql_function!` instead. See `CHANGELOG.md` for migration instructions"
7781
)]
7882
#[cfg(all(feature = "with-deprecated", not(feature = "without-deprecated")))]
7983
macro_rules! no_arg_sql_function {

diesel/src/expression/helper_types.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub type Eq<Lhs, Rhs> = Grouped<super::operators::Eq<Lhs, AsExpr<Rhs, Lhs>>>;
2626
/// [`lhs.ne(rhs)`](crate::expression_methods::ExpressionMethods::ne())
2727
pub type NotEq<Lhs, Rhs> = Grouped<super::operators::NotEq<Lhs, AsExpr<Rhs, Lhs>>>;
2828

29+
#[doc(hidden)] // required for `#[auto_type]`
30+
pub type Ne<Lhs, Rhs> = NotEq<Lhs, Rhs>;
31+
2932
/// The return type of
3033
/// [`lhs.eq_any(rhs)`](crate::expression_methods::ExpressionMethods::eq_any())
3134
pub type EqAny<Lhs, Rhs> = Grouped<In<Lhs, <Rhs as AsInExpression<SqlTypeOf<Lhs>>>::InExpression>>;
@@ -35,6 +38,9 @@ pub type EqAny<Lhs, Rhs> = Grouped<In<Lhs, <Rhs as AsInExpression<SqlTypeOf<Lhs>
3538
pub type NeAny<Lhs, Rhs> =
3639
Grouped<NotIn<Lhs, <Rhs as AsInExpression<SqlTypeOf<Lhs>>>::InExpression>>;
3740

41+
#[doc(hidden)] // required for `#[auto_type]`
42+
pub type NeAll<Lhs, Rhs> = NeAny<Lhs, Rhs>;
43+
3844
/// The return type of
3945
/// [`expr.is_null()`](crate::expression_methods::ExpressionMethods::is_null())
4046
pub type IsNull<Expr> = Grouped<super::operators::IsNull<Expr>>;
@@ -51,6 +57,9 @@ pub type Gt<Lhs, Rhs> = Grouped<super::operators::Gt<Lhs, AsExpr<Rhs, Lhs>>>;
5157
/// [`lhs.ge(rhs)`](crate::expression_methods::ExpressionMethods::ge())
5258
pub type GtEq<Lhs, Rhs> = Grouped<super::operators::GtEq<Lhs, AsExpr<Rhs, Lhs>>>;
5359

60+
#[doc(hidden)] // required for `#[auto_type]`
61+
pub type Ge<Lhs, Rhs> = GtEq<Lhs, Rhs>;
62+
5463
/// The return type of
5564
/// [`lhs.lt(rhs)`](crate::expression_methods::ExpressionMethods::lt())
5665
pub type Lt<Lhs, Rhs> = Grouped<super::operators::Lt<Lhs, AsExpr<Rhs, Lhs>>>;
@@ -59,6 +68,9 @@ pub type Lt<Lhs, Rhs> = Grouped<super::operators::Lt<Lhs, AsExpr<Rhs, Lhs>>>;
5968
/// [`lhs.le(rhs)`](crate::expression_methods::ExpressionMethods::le())
6069
pub type LtEq<Lhs, Rhs> = Grouped<super::operators::LtEq<Lhs, AsExpr<Rhs, Lhs>>>;
6170

71+
#[doc(hidden)] // required for `#[auto_type]`
72+
pub type Le<Lhs, Rhs> = LtEq<Lhs, Rhs>;
73+
6274
/// The return type of
6375
/// [`lhs.between(lower, upper)`](crate::expression_methods::ExpressionMethods::between())
6476
pub type Between<Lhs, Lower, Upper> = Grouped<
@@ -122,12 +134,12 @@ pub type Like<Lhs, Rhs> = Grouped<super::operators::Like<Lhs, AsExprOf<Rhs, SqlT
122134
pub type NotLike<Lhs, Rhs> = Grouped<super::operators::NotLike<Lhs, AsExprOf<Rhs, SqlTypeOf<Lhs>>>>;
123135

124136
/// The return type of [`case_when()`](expression::case_when::case_when)
125-
#[allow(non_camel_case_types)]
137+
#[allow(non_camel_case_types)] // required for `#[auto_type]`
126138
pub type case_when<C, T, ST = <T as Expression>::SqlType> = expression::case_when::CaseWhen<
127139
expression::case_when::CaseWhenConditionsLeaf<Grouped<C>, Grouped<AsExprOf<T, ST>>>,
128140
expression::case_when::NoElseExpression,
129141
>;
130-
/// The return type of [`case_when(...).when(...)`](expression::case_when::CaseWhen::when)
142+
/// The return type of [`case_when(...).when(...)`](expression::CaseWhen::when)
131143
pub type When<W, C, T> = expression::case_when::CaseWhen<
132144
expression::case_when::CaseWhenConditionsIntermediateNode<
133145
Grouped<C>,

diesel/src/expression/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) mod dsl {
5353
use crate::dsl::SqlTypeOf;
5454

5555
#[doc(inline)]
56-
pub use super::case_when::*;
56+
pub use super::case_when::case_when;
5757
#[doc(inline)]
5858
pub use super::count::*;
5959
#[doc(inline)]
@@ -65,6 +65,8 @@ pub(crate) mod dsl {
6565
#[doc(inline)]
6666
pub use super::functions::date_and_time::*;
6767
#[doc(inline)]
68+
pub use super::helper_types::{case_when, Otherwise, When};
69+
#[doc(inline)]
6870
pub use super::not::not;
6971
#[doc(inline)]
7072
pub use super::sql_literal::sql;
@@ -73,7 +75,7 @@ pub(crate) mod dsl {
7375
pub use crate::pg::expression::dsl::*;
7476

7577
/// The return type of [`count(expr)`](crate::dsl::count())
76-
pub type count<Expr> = super::count::count::HelperType<SqlTypeOf<Expr>, Expr>;
78+
pub type count<Expr> = super::count::count<SqlTypeOf<Expr>, Expr>;
7779

7880
/// The return type of [`count_star()`](crate::dsl::count_star())
7981
pub type count_star = super::count::CountStar;
@@ -82,12 +84,14 @@ pub(crate) mod dsl {
8284
pub type count_distinct<Expr> = super::count::CountDistinct<SqlTypeOf<Expr>, Expr>;
8385

8486
/// The return type of [`date(expr)`](crate::dsl::date())
85-
pub type date<Expr> = super::functions::date_and_time::date::HelperType<Expr>;
87+
pub type date<Expr> = super::functions::date_and_time::date<Expr>;
8688

8789
#[cfg(feature = "mysql_backend")]
8890
pub use crate::mysql::query_builder::DuplicatedKeys;
8991
}
9092

93+
#[doc(inline)]
94+
pub use self::case_when::CaseWhen;
9195
#[doc(inline)]
9296
pub use self::sql_literal::{SqlLiteral, UncheckedBind};
9397

0 commit comments

Comments
 (0)