opaleye-0.5.3.0: An SQL-generating DSL targeting PostgreSQL

Safe HaskellNone
LanguageHaskell2010

Opaleye.Order

Contents

Description

Ordering, LIMIT and OFFSET

Synopsis

Order by

orderBy :: Order a -> Query a -> Query a Source #

Order the rows of a Query according to the Order.

import Data.Monoid ((<>))

-- Order by the first column ascending.  When first columns are equal
-- order by second column descending.
example :: Query (Column PGInt4, Column PGText)
        -> Query (Column PGInt4, Column PGText)
example = orderBy (asc fst <> desc snd)

data Order a Source #

An Order a represents a sort order and direction for the elements of the type a. Multiple Orders can be composed with mappend or (<>) from Data.Monoid. If two rows are equal according to the first Order in the mappend, the second is used, and so on.

Instances

Divisible Order Source # 

Methods

divide :: (a -> (b, c)) -> Order b -> Order c -> Order a #

conquer :: Order a #

Decidable Order Source # 

Methods

lose :: (a -> Void) -> Order a #

choose :: (a -> Either b c) -> Order b -> Order c -> Order a #

Contravariant Order Source # 

Methods

contramap :: (a -> b) -> Order b -> Order a #

(>$) :: b -> Order b -> Order a #

Semigroup (Order a) Source # 

Methods

(<>) :: Order a -> Order a -> Order a #

sconcat :: NonEmpty (Order a) -> Order a #

stimes :: Integral b => b -> Order a -> Order a #

Monoid (Order a) Source # 

Methods

mempty :: Order a #

mappend :: Order a -> Order a -> Order a #

mconcat :: [Order a] -> Order a #

Order direction

asc :: PGOrd b => (a -> Column b) -> Order a Source #

Specify an ascending ordering by the given expression. (Any NULLs appear last)

desc :: PGOrd b => (a -> Column b) -> Order a Source #

Specify an descending ordering by the given expression. (Any NULLs appear first)

ascNullsFirst :: PGOrd b => (a -> Column b) -> Order a Source #

Specify an ascending ordering by the given expression. (Any NULLs appear first)

descNullsLast :: PGOrd b => (a -> Column b) -> Order a Source #

Specify an descending ordering by the given expression. (Any NULLs appear last)

Limit and offset

limit :: Int -> Query a -> Query a Source #

Limit the results of the given query to the given maximum number of items.

offset :: Int -> Query a -> Query a Source #

Offset the results of the given query by the given amount, skipping that many result rows.

Other