1{-# language NamedFieldPuns #-}
2{-# language ScopedTypeVariables #-}
3{-# language TypeApplications #-}
4{-# language TypeFamilies #-}
13import Data.Functor.Const ( Const( Const ), getConst )
14import Data.Functor.Contravariant ( (>$<), contramap )
18import Rel8.Expr.Order ( asc, desc, nullsFirst, nullsLast )
19import Rel8.Order ( Order )
20import Rel8.Schema.Context ( unDB )
21import Rel8.Schema.Dict ( Dict( Dict ) )
22import Rel8.Schema.HTable (htabulateA, hfield, hdicts, hspecs)
23import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
24import Rel8.Schema.Spec ( SSpec(..) )
25import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
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 {nullability} -> case hfield ords field of
37 Dict -> Const $ unDB . (`hfield` field) >$< case nullability of
38 Nullable -> nullsFirst asc
41 ords = hdicts @(Columns a) @(ConstrainDBType DBOrd)
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 {nullability} -> case hfield ords field of
50 Dict -> Const $ unDB . (`hfield` field) >$< case nullability of
51 Nullable -> nullsLast desc
54 ords = hdicts @(Columns a) @(ConstrainDBType DBOrd)
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