{-# LANGUAGE
DataKinds
, GADTs
, LambdaCase
, OverloadedStrings
, StandaloneDeriving
#-}
module Squeal.PostgreSQL.Expression.Sort
( SortExpression (..)
, OrderBy (..)
) where
import Squeal.PostgreSQL.Expression
import Squeal.PostgreSQL.Render
import Squeal.PostgreSQL.Schema
data SortExpression outer commons grp schemas params from where
Asc
:: Expression outer commons grp schemas params from ('NotNull ty)
-> SortExpression outer commons grp schemas params from
Desc
:: Expression outer commons grp schemas params from ('NotNull ty)
-> SortExpression outer commons grp schemas params from
AscNullsFirst
:: Expression outer commons grp schemas params from ('Null ty)
-> SortExpression outer commons grp schemas params from
AscNullsLast
:: Expression outer commons grp schemas params from ('Null ty)
-> SortExpression outer commons grp schemas params from
DescNullsFirst
:: Expression outer commons grp schemas params from ('Null ty)
-> SortExpression outer commons grp schemas params from
DescNullsLast
:: Expression outer commons grp schemas params from ('Null ty)
-> SortExpression outer commons grp schemas params from
deriving instance Show (SortExpression outer commons grp schemas params from)
instance RenderSQL (SortExpression outer commons grp schemas params from) where
renderSQL = \case
Asc expression -> renderSQL expression <+> "ASC"
Desc expression -> renderSQL expression <+> "DESC"
AscNullsFirst expression -> renderSQL expression
<+> "ASC NULLS FIRST"
DescNullsFirst expression -> renderSQL expression
<+> "DESC NULLS FIRST"
AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
class OrderBy expr where
orderBy
:: [SortExpression outer commons grp schemas params from]
-> expr outer commons grp schemas params from
-> expr outer commons grp schemas params from