module Opaleye.Order (module Opaleye.Order, O.Order) where
import qualified Opaleye.Column as C
import Opaleye.QueryArr (Query)
import qualified Opaleye.Internal.QueryArr as Q
import qualified Opaleye.Internal.Order as O
import qualified Opaleye.PGTypes as T
import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ
orderBy :: O.Order a -> Query a -> Query a
orderBy os q =
Q.simpleQueryArr (O.orderByU os . Q.runSimpleQueryArr q)
asc :: PGOrd b => (a -> C.Column b) -> O.Order a
asc = O.order HPQ.OrderOp { HPQ.orderDirection = HPQ.OpAsc
, HPQ.orderNulls = HPQ.NullsLast }
desc :: PGOrd b => (a -> C.Column b) -> O.Order a
desc = O.order HPQ.OrderOp { HPQ.orderDirection = HPQ.OpDesc
, HPQ.orderNulls = HPQ.NullsFirst }
ascNullsFirst :: PGOrd b => (a -> C.Column b) -> O.Order a
ascNullsFirst = O.order HPQ.OrderOp { HPQ.orderDirection = HPQ.OpAsc
, HPQ.orderNulls = HPQ.NullsFirst }
descNullsLast :: PGOrd b => (a -> C.Column b) -> O.Order a
descNullsLast = O.order HPQ.OrderOp { HPQ.orderDirection = HPQ.OpDesc
, HPQ.orderNulls = HPQ.NullsLast }
limit :: Int -> Query a -> Query a
limit n a = Q.simpleQueryArr (O.limit' n . Q.runSimpleQueryArr a)
offset :: Int -> Query a -> Query a
offset n a = Q.simpleQueryArr (O.offset' n . Q.runSimpleQueryArr a)
class PGOrd a where
instance PGOrd T.PGBool
instance PGOrd T.PGDate
instance PGOrd T.PGFloat8
instance PGOrd T.PGFloat4
instance PGOrd T.PGInt8
instance PGOrd T.PGInt4
instance PGOrd T.PGInt2
instance PGOrd T.PGNumeric
instance PGOrd T.PGText
instance PGOrd T.PGTime
instance PGOrd T.PGTimestamptz
instance PGOrd T.PGTimestamp
instance PGOrd T.PGCitext