1{-# language ScopedTypeVariables #-}
2{-# language TypeApplications #-}
3{-# language ViewPatterns #-}
5module Rel8.Type.ReadShow ( ReadShow(..) ) where
8import Data.Proxy ( Proxy( Proxy ) )
9import Data.Typeable ( Typeable, typeRep )
11import Text.Read ( readMaybe )
14import Rel8.Type ( DBType( typeInformation ) )
15import Rel8.Type.Information ( parseTypeInformation )
18import qualified Data.Text as Text
21-- | A deriving-via helper type for column types that store a Haskell value
22-- using a Haskell's 'Read' and 'Show' type classes.
23newtype ReadShow a = ReadShow { fromReadShow :: a }
26instance (Read a, Show a, Typeable a) => DBType (ReadShow a) where
27 typeInformation = parseTypeInformation parser printer typeInformation
29 parser (Text.unpack -> t) = case readMaybe t of
30 Just ok -> Right $ ReadShow ok
31 Nothing -> Left $ "Could not read " <> t <> " as a " <> show (typeRep (Proxy @a))
32 printer = Text.pack . show . fromReadShow
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