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