Skip to content

Commit f26f7d2

Browse files
committed
Fix most type-defs for #[auto_type] by cleaning up all the type defs
1 parent fed0407 commit f26f7d2

File tree

16 files changed

+567
-89
lines changed

16 files changed

+567
-89
lines changed

diesel/src/expression/exists.rs

+2-2
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/helper_types.rs

+30-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,43 @@ use crate::expression::grouped::Grouped;
55
use crate::expression::operators;
66

77
/// The return type of [`not(expr)`](crate::dsl::not())
8-
pub type not<Expr> = operators::Not<Grouped<Expr>>;
8+
pub type Not<Expr> = operators::Not<Grouped<Expr>>;
9+
10+
#[doc(hidden)]
11+
#[deprecated(note = "use `dsl::Not` instead")]
12+
pub type not<Expr> = Not<Expr>;
913

1014
/// The return type of [`max(expr)`](crate::dsl::max())
11-
pub type max<Expr> = super::aggregate_ordering::max::HelperType<SqlTypeOf<Expr>, Expr>;
15+
pub type Max<Expr> = super::aggregate_ordering::max::HelperType<SqlTypeOf<Expr>, Expr>;
16+
17+
#[doc(hidden)]
18+
#[deprecated(note = "use `dsl::Max` instead")]
19+
pub type max<Expr> = Max<Expr>;
1220

1321
/// The return type of [`min(expr)`](crate::dsl::min())
14-
pub type min<Expr> = super::aggregate_ordering::min::HelperType<SqlTypeOf<Expr>, Expr>;
22+
pub type Min<Expr> = super::aggregate_ordering::min::HelperType<SqlTypeOf<Expr>, Expr>;
23+
24+
#[doc(hidden)]
25+
#[deprecated(note = "use `dsl::Min` instead")]
26+
pub type min<Expr> = Min<Expr>;
1527

1628
/// The return type of [`sum(expr)`](crate::dsl::sum())
17-
pub type sum<Expr> = super::aggregate_folding::sum::HelperType<SqlTypeOf<Expr>, Expr>;
29+
pub type Sum<Expr> = super::aggregate_folding::sum::HelperType<SqlTypeOf<Expr>, Expr>;
30+
31+
#[doc(hidden)]
32+
#[deprecated(note = "use `dsl::Not` instead")]
33+
pub type sum<Expr> = Sum<Expr>;
1834

1935
/// The return type of [`avg(expr)`](crate::dsl::avg())
20-
pub type avg<Expr> = super::aggregate_folding::avg::HelperType<SqlTypeOf<Expr>, Expr>;
36+
pub type Avg<Expr> = super::aggregate_folding::avg::HelperType<SqlTypeOf<Expr>, Expr>;
37+
38+
#[doc(hidden)]
39+
#[deprecated(note = "use `dsl::Not` instead")]
40+
pub type avg<Expr> = Avg<Expr>;
2141

2242
/// The return type of [`exists(expr)`](crate::dsl::exists())
23-
pub type exists<Expr> = crate::expression::exists::Exists<Expr>;
43+
pub type Exists<Expr> = crate::expression::exists::Exists<Expr>;
44+
45+
#[doc(hidden)]
46+
#[deprecated(note = "use `dsl::Exists` instead")]
47+
pub type exists<Expr> = Exists<Expr>;

diesel/src/expression/helper_types.rs

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub type Eq<Lhs, Rhs> = Grouped<super::operators::Eq<Lhs, AsExpr<Rhs, Lhs>>>;
2525
/// [`lhs.ne(rhs)`](crate::expression_methods::ExpressionMethods::ne())
2626
pub type NotEq<Lhs, Rhs> = Grouped<super::operators::NotEq<Lhs, AsExpr<Rhs, Lhs>>>;
2727

28+
#[doc(hidden)]
29+
pub type Ne<Lhs, Rhs> = NotEq<Lhs, Rhs>;
30+
2831
/// The return type of
2932
/// [`lhs.eq_any(rhs)`](crate::expression_methods::ExpressionMethods::eq_any())
3033
pub type EqAny<Lhs, Rhs> = Grouped<In<Lhs, <Rhs as AsInExpression<SqlTypeOf<Lhs>>>::InExpression>>;
@@ -34,6 +37,9 @@ pub type EqAny<Lhs, Rhs> = Grouped<In<Lhs, <Rhs as AsInExpression<SqlTypeOf<Lhs>
3437
pub type NeAny<Lhs, Rhs> =
3538
Grouped<NotIn<Lhs, <Rhs as AsInExpression<SqlTypeOf<Lhs>>>::InExpression>>;
3639

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

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

70+
#[doc(hidden)] // required for `#[auto_type]`
71+
pub type Le<Lhs, Rhs> = LtEq<Lhs, Rhs>;
72+
6173
/// The return type of
6274
/// [`lhs.between(lower, upper)`](crate::expression_methods::ExpressionMethods::between())
6375
pub type Between<Lhs, Lower, Upper> = Grouped<

diesel/src/expression/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,29 @@ pub(crate) mod dsl {
7070
pub use crate::pg::expression::dsl::*;
7171

7272
/// The return type of [`count(expr)`](crate::dsl::count())
73-
pub type count<Expr> = super::count::count::HelperType<SqlTypeOf<Expr>, Expr>;
73+
pub type Count<Expr> = super::count::count::HelperType<SqlTypeOf<Expr>, Expr>;
74+
#[doc(hidden)]
75+
#[deprecated(note = "use `dsl::Count` instead")]
76+
pub type count<Expr> = Count<Expr>;
7477

7578
/// The return type of [`count_star()`](crate::dsl::count_star())
76-
pub type count_star = super::count::CountStar;
79+
pub type CountStar = super::count::CountStar;
80+
#[doc(hidden)]
81+
#[deprecated(note = "use `dsl::CountStar` instead")]
82+
pub type count_star = CountStar;
7783

7884
/// The return type of [`count_distinct()`](crate::dsl::count_distinct())
79-
pub type count_distinct<Expr> = super::count::CountDistinct<SqlTypeOf<Expr>, Expr>;
85+
pub type CountDistinct<Expr> = super::count::CountDistinct<SqlTypeOf<Expr>, Expr>;
86+
87+
#[doc(hidden)]
88+
#[deprecated(note = "use `dsl::CountDistinct` instead")]
89+
pub type count_distinct<Expr> = CountDistinct<Expr>;
8090

8191
/// The return type of [`date(expr)`](crate::dsl::date())
82-
pub type date<Expr> = super::functions::date_and_time::date::HelperType<Expr>;
92+
pub type Date<Expr> = super::functions::date_and_time::date::HelperType<Expr>;
93+
#[doc(hidden)]
94+
#[deprecated(note = "Use `dsl::Date` instead")]
95+
pub type date<Expr> = Date<Expr>;
8396

8497
#[cfg(feature = "mysql_backend")]
8598
pub use crate::mysql::query_builder::DuplicatedKeys;

diesel/src/expression/not.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::expression::grouped::Grouped;
22
use crate::expression::Expression;
3-
use crate::helper_types::not;
3+
use crate::helper_types;
44
use crate::sql_types::BoolOrNullableBool;
55

66
/// Creates a SQL `NOT` expression
@@ -23,7 +23,7 @@ use crate::sql_types::BoolOrNullableBool;
2323
/// assert_eq!(Ok(2), users_not_with_name.first(connection));
2424
/// # }
2525
/// ```
26-
pub fn not<T>(expr: T) -> not<T>
26+
pub fn not<T>(expr: T) -> helper_types::Not<T>
2727
where
2828
T: Expression,
2929
<T as Expression>::SqlType: BoolOrNullableBool,

diesel/src/lib.rs

+51-3
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub use diesel_derives::{
315315

316316
pub use diesel_derives::MultiConnection;
317317

318-
#[allow(unknown_lints, ambiguous_glob_reexports)]
318+
#[allow(unknown_lints, ambiguous_glob_reexports, missing_docs)]
319319
pub mod dsl {
320320
//! Includes various helper types and bare functions which are named too
321321
//! generically to be included in prelude, but are often used when using Diesel.
@@ -335,6 +335,7 @@ pub mod dsl {
335335
pub use diesel_derives::auto_type;
336336
}
337337

338+
#[allow(missing_docs)]
338339
pub mod helper_types {
339340
//! Provide helper types for concisely writing the return type of functions.
340341
//! As with iterators, it is unfortunately difficult to return a partially
@@ -407,10 +408,10 @@ pub mod helper_types {
407408
pub type ThenOrderBy<Source, Ordering> = <Source as ThenOrderDsl<Ordering>>::Output;
408409

409410
/// Represents the return type of [`.limit()`](crate::prelude::QueryDsl::limit)
410-
pub type Limit<Source> = <Source as LimitDsl>::Output;
411+
pub type Limit<Source, DummyArg = i64> = <Source as LimitDsl<DummyArg>>::Output;
411412

412413
/// Represents the return type of [`.offset()`](crate::prelude::QueryDsl::offset)
413-
pub type Offset<Source> = <Source as OffsetDsl>::Output;
414+
pub type Offset<Source, DummyArg = i64> = <Source as OffsetDsl<DummyArg>>::Output;
414415

415416
/// Represents the return type of [`.inner_join(rhs)`](crate::prelude::QueryDsl::inner_join)
416417
pub type InnerJoin<Source, Rhs> =
@@ -622,6 +623,53 @@ pub mod helper_types {
622623
#[deprecated(note = "Use `LoadQuery::RowIter` directly")]
623624
pub type LoadIter<'conn, 'query, Q, Conn, U, B = crate::connection::DefaultLoadingMode> =
624625
<Q as load_dsl::LoadQuery<'query, Conn, U, B>>::RowIter<'conn>;
626+
627+
/// todo
628+
pub type Delete<T> = crate::query_builder::DeleteStatement<
629+
<T as HasTable>::Table,
630+
<T as IntoUpdateTarget>::WhereClause,
631+
>;
632+
633+
pub type InsertInto<T> = crate::query_builder::IncompleteInsertStatement<T>;
634+
635+
pub type InsertOrIgnoreInto<T> = crate::query_builder::IncompleteInsertOrIgnoreStatement<T>;
636+
pub type ReplaceInto<T> = crate::query_builder::IncompleteReplaceStatement<T>;
637+
638+
pub trait InsertAutoTypeHelper {
639+
type Table;
640+
type Op;
641+
}
642+
643+
impl<T, Op> InsertAutoTypeHelper for crate::query_builder::IncompleteInsertStatement<T, Op> {
644+
type Table = T;
645+
type Op = Op;
646+
}
647+
648+
pub type Values<I, U> = crate::query_builder::InsertStatement<
649+
<I as InsertAutoTypeHelper>::Table,
650+
<U as crate::Insertable<<I as InsertAutoTypeHelper>::Table>>::Values,
651+
<I as InsertAutoTypeHelper>::Op,
652+
>;
653+
654+
pub trait UpdateAutoTypeHelper {
655+
type Table;
656+
type Where;
657+
}
658+
659+
impl<T, W> UpdateAutoTypeHelper for crate::query_builder::UpdateStatement<T, W>
660+
where
661+
T: crate::QuerySource,
662+
{
663+
type Table = T;
664+
665+
type Where = W;
666+
}
667+
668+
pub type Set<U, V> = crate::query_builder::UpdateStatement<
669+
<U as UpdateAutoTypeHelper>::Table,
670+
<U as UpdateAutoTypeHelper>::Where,
671+
<V as crate::AsChangeset>::Changeset,
672+
>;
625673
}
626674

627675
pub mod prelude {

diesel/src/pg/expression/expression_methods.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use super::date_and_time::{AtTimeZone, DateTimeLike};
88
use super::operators::*;
99
use crate::dsl;
1010
use crate::expression::grouped::Grouped;
11-
use crate::expression::operators::{Asc, Desc};
11+
use crate::expression::operators::{Asc, Concat, Desc, Like, NotLike};
1212
use crate::expression::{AsExpression, Expression, IntoSql, TypedExpressionType};
1313
use crate::pg::expression::expression_methods::private::BinaryOrNullableBinary;
14-
use crate::sql_types::{Array, Binary, Inet, Integer, Jsonb, SqlType, Text, VarChar};
14+
use crate::sql_types::{Array, Inet, Integer, SqlType, Text, VarChar};
1515
use crate::EscapeExpressionMethods;
1616

1717
/// PostgreSQL specific methods which are present on all expressions.
@@ -253,7 +253,7 @@ pub trait PgArrayExpressionMethods: Expression + Sized {
253253
/// # Ok(())
254254
/// # }
255255
/// ```
256-
fn contains<T>(self, other: T) -> dsl::ArrayContains<Self, T>
256+
fn contains<T>(self, other: T) -> dsl::Contains<Self, T>
257257
where
258258
Self::SqlType: SqlType,
259259
T: AsExpression<Self::SqlType>,
@@ -363,7 +363,7 @@ pub trait PgArrayExpressionMethods: Expression + Sized {
363363
/// # Ok(())
364364
/// # }
365365
/// ```
366-
fn index<T>(self, other: T) -> dsl::ArrayIndex<Self, T>
366+
fn index<T>(self, other: T) -> dsl::Index<Self, T>
367367
where
368368
Self::SqlType: SqlType,
369369
T: AsExpression<Integer>,
@@ -409,12 +409,12 @@ pub trait PgArrayExpressionMethods: Expression + Sized {
409409
/// # Ok(())
410410
/// # }
411411
///
412-
fn concat<T>(self, other: T) -> dsl::ConcatArray<Self, T>
412+
fn concat<T>(self, other: T) -> dsl::Concat<Self, T>
413413
where
414414
Self::SqlType: SqlType,
415415
T: AsExpression<Self::SqlType>,
416416
{
417-
Grouped(ConcatArray::new(self, other.as_expression()))
417+
Grouped(Concat::new(self, other.as_expression()))
418418
}
419419
}
420420

@@ -1303,11 +1303,12 @@ pub trait PgJsonbExpressionMethods: Expression + Sized {
13031303
/// # Ok(())
13041304
/// # }
13051305
/// ```
1306-
fn concat<T>(self, other: T) -> dsl::ConcatJsonb<Self, T>
1306+
fn concat<T>(self, other: T) -> dsl::Concat<Self, T>
13071307
where
1308-
T: AsExpression<Jsonb>,
1308+
Self::SqlType: SqlType,
1309+
T: AsExpression<Self::SqlType>,
13091310
{
1310-
Grouped(ConcatJsonb::new(self, other.as_expression()))
1311+
Grouped(Concat::new(self, other.as_expression()))
13111312
}
13121313

13131314
/// Creates a PostgreSQL `?` expression.
@@ -1546,11 +1547,12 @@ pub trait PgJsonbExpressionMethods: Expression + Sized {
15461547
/// # Ok(())
15471548
/// # }
15481549
/// ```
1549-
fn contains<T>(self, other: T) -> dsl::ContainsJsonb<Self, T>
1550+
fn contains<T>(self, other: T) -> dsl::Contains<Self, T>
15501551
where
1551-
T: AsExpression<Jsonb>,
1552+
Self::SqlType: SqlType,
1553+
T: AsExpression<Self::SqlType>,
15521554
{
1553-
Grouped(ContainsJsonb::new(self, other.as_expression()))
1555+
Grouped(Contains::new(self, other.as_expression()))
15541556
}
15551557

15561558
/// Creates a PostgreSQL `<@` expression.
@@ -1611,11 +1613,12 @@ pub trait PgJsonbExpressionMethods: Expression + Sized {
16111613
/// # }
16121614
/// ```
16131615
#[allow(clippy::wrong_self_convention)] // This is named after the sql operator
1614-
fn is_contained_by<T>(self, other: T) -> dsl::IsContainedByJsonb<Self, T>
1616+
fn is_contained_by<T>(self, other: T) -> dsl::IsContainedBy<Self, T>
16151617
where
1616-
T: AsExpression<Jsonb>,
1618+
Self::SqlType: SqlType,
1619+
T: AsExpression<Self::SqlType>,
16171620
{
1618-
Grouped(IsContainedByJsonb::new(self, other.as_expression()))
1621+
Grouped(IsContainedBy::new(self, other.as_expression()))
16191622
}
16201623

16211624
/// Creates a PostgreSQL `-` expression.
@@ -2277,12 +2280,12 @@ pub trait PgBinaryExpressionMethods: Expression + Sized {
22772280
/// assert_eq!(Ok(expected_names), names);
22782281
/// # }
22792282
/// ```
2280-
fn concat<T>(self, other: T) -> dsl::ConcatBinary<Self, T>
2283+
fn concat<T>(self, other: T) -> dsl::Concat<Self, T>
22812284
where
22822285
Self::SqlType: SqlType,
2283-
T: AsExpression<Binary>,
2286+
T: AsExpression<Self::SqlType>,
22842287
{
2285-
Grouped(ConcatBinary::new(self, other.as_expression()))
2288+
Grouped(Concat::new(self, other.as_expression()))
22862289
}
22872290

22882291
/// Creates a PostgreSQL binary `LIKE` expression.
@@ -2327,12 +2330,12 @@ pub trait PgBinaryExpressionMethods: Expression + Sized {
23272330
/// assert_eq!(Ok(vec![b"Sean".to_vec()]), starts_with_s);
23282331
/// # }
23292332
/// ```
2330-
fn like<T>(self, other: T) -> dsl::LikeBinary<Self, T>
2333+
fn like<T>(self, other: T) -> dsl::Like<Self, T>
23312334
where
23322335
Self::SqlType: SqlType,
2333-
T: AsExpression<Binary>,
2336+
T: AsExpression<Self::SqlType>,
23342337
{
2335-
Grouped(LikeBinary::new(self, other.as_expression()))
2338+
Grouped(Like::new(self, other.as_expression()))
23362339
}
23372340

23382341
/// Creates a PostgreSQL binary `LIKE` expression.
@@ -2377,12 +2380,12 @@ pub trait PgBinaryExpressionMethods: Expression + Sized {
23772380
/// assert_eq!(Ok(vec![b"Tess".to_vec()]), starts_with_s);
23782381
/// # }
23792382
/// ```
2380-
fn not_like<T>(self, other: T) -> dsl::NotLikeBinary<Self, T>
2383+
fn not_like<T>(self, other: T) -> dsl::NotLike<Self, T>
23812384
where
23822385
Self::SqlType: SqlType,
2383-
T: AsExpression<Binary>,
2386+
T: AsExpression<Self::SqlType>,
23842387
{
2385-
Grouped(NotLikeBinary::new(self, other.as_expression()))
2388+
Grouped(NotLike::new(self, other.as_expression()))
23862389
}
23872390
}
23882391

@@ -2394,7 +2397,7 @@ where
23942397
{
23952398
}
23962399

2397-
mod private {
2400+
pub(in crate::pg) mod private {
23982401
use crate::sql_types::{
23992402
Array, Binary, Cidr, Inet, Integer, Json, Jsonb, Nullable, Range, SqlType, Text,
24002403
};

0 commit comments

Comments
 (0)