1{-# language DataKinds #-}
2{-# language ScopedTypeVariables #-}
3{-# language TypeApplications #-}
4{-# language TypeFamilies #-}
13import Data.Functor.Const ( Const( Const ), getConst )
14import Data.Functor.Contravariant ( (>$<), contramap )
18import Rel8.Expr ( unE )
19import Rel8.Expr.Order ( asc, desc, nullsFirst, nullsLast )
20import Rel8.Order ( Order )
21import Rel8.Schema.Dict ( Dict( Dict ) )
22import Rel8.Schema.HTable (htabulateA, hfield, hspecs)
23import Rel8.Schema.Null ( Nullity( Null, NotNull ) )
24import Rel8.Schema.Spec ( SSpec( SSpec ) )
25import Rel8.Schema.Spec.ConstrainDBType ( dbTypeDict, dbTypeNullity )
26import Rel8.Table ( Columns, toColumns )
30-- | Construct an 'Order' for a 'Table' by sorting all columns into ascending
31-- orders (any nullable columns will be sorted with @NULLS FIRST@).
32ascTable :: forall a. OrdTable a => Order a
33ascTable = contramap toColumns $ getConst $
34 htabulateA @(Columns a) $ \field -> case hfield hspecs field of
35 SSpec {} -> case hfield (ordTable @a) field of
36 dict@Dict -> case dbTypeDict dict of
37 Dict -> Const $ unE . (`hfield` field) >$<
38 case dbTypeNullity dict of
39 Null -> nullsFirst asc
43-- | Construct an 'Order' for a 'Table' by sorting all columns into descending
44-- orders (any nullable columns will be sorted with @NULLS LAST@).
45descTable :: forall a. OrdTable a => Order a
46descTable = contramap toColumns $ getConst $
47 htabulateA @(Columns a) $ \field -> case hfield hspecs field of
48 SSpec {} -> case hfield (ordTable @a) field of
49 dict@Dict -> case dbTypeDict dict of
50 Dict -> Const $ unE . (`hfield` field) >$<
51 case dbTypeNullity dict of
52 Null -> nullsLast desc
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