1{-# language FlexibleContexts #-}
2{-# language NamedFieldPuns #-}
3{-# language ScopedTypeVariables #-}
4{-# language TypeApplications #-}
5{-# language TypeFamilies #-}
6{-# language ViewPatterns #-}
18import Data.Foldable ( fold )
19import Data.Functor.Const ( Const( Const ), getConst )
20import Data.List.NonEmpty ( NonEmpty, intersperse )
24import Text.Casing ( quietSnake )
27import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
30import Rel8.Expr ( Expr, Col(..) )
31import Rel8.Expr.Opaleye ( toPrimExpr )
32import Rel8.Kind.Labels ( renderLabels )
33import Rel8.Schema.HTable ( htabulate, htabulateA, hfield, hspecs )
34import Rel8.Schema.Name ( Name, Col(..) )
35import Rel8.Schema.Spec ( SSpec(..) )
36import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
39namesFromLabels :: Table Name a => a
40namesFromLabels = namesFromLabelsWith go
42 go = fold . intersperse "/" . fmap quietSnake
45namesFromLabelsWith :: Table Name a
46 => (NonEmpty String -> String) -> a
47namesFromLabelsWith f = fromColumns $ htabulate $ \field ->
48 case hfield hspecs field of
49 SSpec {labels} -> NameCol (f (renderLabels labels))
52showExprs :: Table Expr a => a -> [(String, Opaleye.PrimExpr)]
53showExprs as = case (namesFromLabels, toColumns as) of
54 (names, exprs) -> getConst $ htabulateA $ \field ->
55 case (hfield names field, hfield exprs field) of
56 (NameCol name, DB expr) -> Const [(name, toPrimExpr expr)]
59showLabels :: forall a. Table (Context a) a => a -> [NonEmpty String]
60showLabels _ = getConst $
61 htabulateA @(Columns a) $ \field -> case hfield hspecs field of
62 SSpec {labels} -> Const [renderLabels labels]
65showNames :: forall a. Table Name a => a -> [String]
66showNames (toColumns -> names) = getConst $
67 htabulateA @(Columns a) $ \field -> case hfield names field of
68 NameCol name -> Const [name]
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