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, hdicts, hspecs)
24import Rel8.Schema.Nullability
25 ( Unnullify, Nullability( Nullable, NonNullable )
26 , Sql, nullabilization
28import Rel8.Schema.Spec ( Spec( Spec ), SSpec( SSpec ) )
29import Rel8.Schema.Spec.ConstrainDBType ( ConstrainDBType )
35-- | Construct an 'Order' for a 'Table' by sorting all columns into ascending
36-- orders (any nullable columns will be sorted with @NULLS FIRST@).
37ascTable :: forall a. OrdTable a => Order a
38ascTable = contramap toColumns $ getConst $
39 htabulateA @(Columns a) $ \field -> case hfield hspecs field of
40 SSpec {} -> case hfield ords field of
41 dict@Dict -> case ord dict of
42 Dict -> Const $ unDB . (`hfield` field) >$< case nullability dict of
43 Nullable -> nullsFirst asc
46 ords = hdicts @(Columns a) @(ConstrainDBType DBOrd)
49-- | Construct an 'Order' for a 'Table' by sorting all columns into descending
50-- orders (any nullable columns will be sorted with @NULLS LAST@).
51descTable :: forall a. OrdTable a => Order a
52descTable = contramap toColumns $ getConst $
53 htabulateA @(Columns a) $ \field -> case hfield hspecs field of
54 SSpec {} -> case hfield ords field of
55 dict@Dict -> case ord dict of
56 Dict -> Const $ unDB . (`hfield` field) >$< case nullability dict of
57 Nullable -> nullsLast desc
60 ords = hdicts @(Columns a) @(ConstrainDBType DBOrd)
63nullability :: Dict (ConstrainDBType DBOrd) ('Spec l n a) -> Nullability a
64nullability = step2 . step1
66 step1 :: Dict (ConstrainDBType DBOrd) ('Spec l n a) -> Dict (Sql DBOrd) a
69 step2 :: Dict (Sql DBOrd) a -> Nullability a
70 step2 Dict = nullabilization
73ord :: Dict (ConstrainDBType DBOrd) ('Spec l n a) -> Dict DBOrd (Unnullify a)
76 step1 :: Dict (ConstrainDBType DBOrd) ('Spec l n a) -> Dict (Sql DBOrd) a
79 step2 :: Dict (Sql DBOrd) a -> Dict DBOrd (Unnullify a)
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