@@ -32,11 +32,17 @@ distinct :: EqTable a => Query a -> Query a
32distinct = mapOpaleye (Opaleye.distinctExplicit distinctspec)
32distinct = mapOpaleye (Opaleye.distinctExplicit distinctspec)
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'.
35distinctOn :: EqTable b => (a -> b) -> Query a -> Query a
38distinctOn :: EqTable b => (a -> b) -> Query a -> Query a
36distinctOn proj =
39distinctOn proj =
37 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOn unpackspec proj . Opaleye.runSimpleQueryArr q))
40 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOn unpackspec proj . Opaleye.runSimpleQueryArr q))
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.
40distinctOnBy :: EqTable b => (a -> b) -> Order a -> Query a -> Query a
46distinctOnBy :: EqTable b => (a -> b) -> Order a -> Query a -> Query a
41distinctOnBy proj (Order order) =
47distinctOnBy proj (Order order) =
42 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOnBy unpackspec proj order . Opaleye.runSimpleQueryArr q))
48 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOnBy unpackspec proj order . Opaleye.runSimpleQueryArr q))