1{-# options_ghc -fno-warn-redundant-constraints #-}
3module Rel8.Query.Distinct
14import qualified Opaleye.Distinct as Opaleye
15import qualified Opaleye.Internal.Order as Opaleye
16import qualified Opaleye.Internal.QueryArr as Opaleye
19import Rel8.Order ( Order( Order ) )
20import Rel8.Query ( Query )
21import Rel8.Query.Opaleye ( mapOpaleye )
22import Rel8.Table.Eq ( EqTable )
23import Rel8.Table.Opaleye ( distinctspec, unpackspec )
26-- | Select all distinct rows from a query, removing duplicates. @distinct q@
27-- is equivalent to the SQL statement @SELECT DISTINCT q@.
28distinct :: EqTable a => Query a -> Query a
29distinct = mapOpaleye (Opaleye.distinctExplicit distinctspec)
32-- | Select all distinct rows from a query, where rows are equivalent according
33-- to a projection. If multiple rows have the same projection, it is
34-- unspecified which row will be returned. If this matters, use 'distinctOnBy'.
35distinctOn :: EqTable b => (a -> b) -> Query a -> Query a
37 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOn unpackspec proj . Opaleye.runSimpleQueryArr q))
40-- | Select all distinct rows from a query, where rows are equivalent according
41-- to a projection. If there are multiple rows with the same projection, the
42-- first row according to the specified 'Order' will be returned.
43distinctOnBy :: EqTable b => (a -> b) -> Order a -> Query a -> Query a
44distinctOnBy proj (Order order) =
45 mapOpaleye (\q -> Opaleye.productQueryArr (Opaleye.distinctOnBy unpackspec proj order . Opaleye.runSimpleQueryArr q))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list