on 2ba99ea help sign in
rel8/src/Rel8/Order.hs
37 lines 1.1 kB history raw
1{-# language DerivingStrategies #-}
2{-# language GeneralizedNewtypeDeriving #-}
3{-# language StandaloneKindSignatures #-}
5module Rel8.Order
6 ( Order(..)
7 , toOrderExprs
8 )
9where
11-- base
12import Data.Functor.Contravariant ( Contravariant )
13import Data.Kind ( Type )
14import Prelude
16-- contravariant
17import Data.Functor.Contravariant.Divisible ( Decidable, Divisible )
19-- opaleye
20import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
21import qualified Opaleye.Internal.Order as Opaleye
24-- | An ordering expression for @a@. Primitive orderings are defined with
25-- 'Rel8.asc' and 'Rel8.desc', and you can combine @Order@ via its various
26-- instances.
27--
28-- A common pattern is to use '<>' to combine multiple orderings in sequence,
29-- and '>$<' (from 'Contravariant') to select individual columns.
30type Order :: Type -> Type
31newtype Order a = Order (Opaleye.Order a)
32 deriving newtype (Contravariant, Divisible, Decidable, Semigroup, Monoid)
35toOrderExprs :: Order a -> a -> [Opaleye.OrderExpr]
36toOrderExprs (Order (Opaleye.Order order)) a =
37 uncurry Opaleye.OrderExpr <$> order a