on 37a8567 help sign in
rel8/src/Rel8/Type/ReadShow.hs
24 lines 686 B history raw
1module Rel8.Type.ReadShow ( ReadShow(..) ) where
3-- base
4import Prelude
5import Text.Read ( readEither )
7-- rel8
8import Rel8.Type ( DBType( typeInformation ) )
9import Rel8.Type.Information ( parseTypeInformation )
11-- text
12import qualified Data.Text as Text
15-- | A deriving-via helper type for column types that store a Haskell value
16-- using a Haskell's 'Read' and 'Show' type classes.
17newtype ReadShow a = ReadShow { fromReadShow :: a }
20instance (Read a, Show a) => DBType (ReadShow a) where
21 typeInformation = parseTypeInformation parser printer typeInformation
22 where
23 parser = fmap ReadShow . readEither . Text.unpack
24 printer = Text.pack . show . fromReadShow