Skip to content

Commit

Permalink
add more tests + cs
Browse files Browse the repository at this point in the history
  • Loading branch information
omid committed May 25, 2023
1 parent 1de31ad commit 630731d
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 109 deletions.
16 changes: 8 additions & 8 deletions diesel/src/pg/query_builder/distinct_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub struct DistinctOnClause<T>(pub(crate) T);
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for NoOrderClause {}
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for OrderClause<(T,)> {}
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for OrderClause<T> where T: crate::Column {}
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for OrderClause<crate::helper_types::Desc<T>>
where
T: crate::Column,
{}
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for OrderClause<crate::helper_types::Asc<T>>
where
T: crate::Column,
{}
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for OrderClause<crate::helper_types::Desc<T>> where
T: crate::Column
{
}
impl<T> ValidOrderingForDistinct<DistinctOnClause<T>> for OrderClause<crate::helper_types::Asc<T>> where
T: crate::Column
{
}
macro_rules! valid_ordering {
(@skip: ($ST1: ident, $($ST:ident,)*), $T1:ident, ) => {};
(@skip: ($ST1: ident, $($ST:ident,)*), $T1:ident, $($T:ident,)+) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ fn main() {
.then_order_by(users::id)
.distinct_on(users::name);

// same as above, with asc/desc
let _ = users::table
.order_by(users::name.asc())
.distinct_on(users::name)
.into_boxed();
let _ = users::table
.order_by((users::name.asc(), users::id.desc()))
.distinct_on(users::name)
.into_boxed();
let _ = users::table
.order_by((users::name.asc(), users::id.desc()))
.distinct_on((users::name, users::id))
.into_boxed();
let _ = users::table
.order_by((users::name.asc(), users::id.desc()))
.distinct_on((users::name, users::id, users::hair_color))
.into_boxed();
let _ = users::table
.order_by((users::name.asc(), users::id.desc(), users::hair_color))
.distinct_on((users::name, users::id))
.into_boxed();
let _ = users::table
.order_by(users::name.asc())
.then_order_by(users::id)
.distinct_on(users::name)
.into_boxed();

// verify that this all works with boxed queries
let _ = users::table.distinct_on(users::name).into_boxed();
let _ = users::table
Expand Down
Loading

0 comments on commit 630731d

Please sign in to comment.