on master help sign in
Document distinctOn and distinctOnBy
commitb76ed4d111dfd3499b9bb1456a08a845c7281b9a authorOllie Charles <ollie@ocharles.org.uk> dateWed 24 Mar 2021, 13:08 (6 years ago) parentf137cd0
1 file changed+6
src/Rel8/Query/Distinct.hs+6
src/Rel8/Query/Distinct.hs+6
@@ -32,11 +32,17 @@ distinct :: EqTable a => Query a -> Query a
3232distinct = mapOpaleye (Opaleye.distinctExplicit distinctspec)
3333
3434
35+-- | Select all distinct rows from a query, where rows are equivalent according
36+-- to a projection. If multiple rows have the same projection, it is
37+-- unspecified which row will be returned. If this matters, use 'distinctOnBy'.
3538distinctOn :: EqTable b => (a -> b) -> Query a -> Query a
3639distinctOn proj =
3740 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOn unpackspec proj . Opaleye.runSimpleQueryArr q))
3841
3942
43+-- | Select all distinct rows from a query, where rows are equivalent according
44+-- to a projection. If there are multiple rows with the same projection, the
45+-- first row according to the specified 'Order' will be returned.
4046distinctOnBy :: EqTable b => (a -> b) -> Order a -> Query a -> Query a
4147distinctOnBy proj (Order order) =
4248 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOnBy unpackspec proj order . Opaleye.runSimpleQueryArr q))