{-# language GADTs #-}
{-# language NamedFieldPuns #-}
{-# language StandaloneKindSignatures #-}
module Rel8.Type.Information
  ( TypeInformation(..)
  , mapTypeInformation
  , parseTypeInformation
  )
where
import Data.Bifunctor ( first )
import Data.Kind ( Type )
import Prelude
import qualified Hasql.Decoders as Hasql
import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
import qualified Data.Text as Text
type TypeInformation :: Type -> Type
data TypeInformation a = TypeInformation
  { TypeInformation a -> a -> PrimExpr
encode :: a -> Opaleye.PrimExpr
    
  , TypeInformation a -> Value a
decode :: Hasql.Value a
    
  , TypeInformation a -> String
typeName :: String
    
  }
mapTypeInformation :: ()
  => (a -> b) -> (b -> a)
  -> TypeInformation a -> TypeInformation b
mapTypeInformation :: (a -> b) -> (b -> a) -> TypeInformation a -> TypeInformation b
mapTypeInformation = (a -> Either String b)
-> (b -> a) -> TypeInformation a -> TypeInformation b
forall a b.
(a -> Either String b)
-> (b -> a) -> TypeInformation a -> TypeInformation b
parseTypeInformation ((a -> Either String b)
 -> (b -> a) -> TypeInformation a -> TypeInformation b)
-> ((a -> b) -> a -> Either String b)
-> (a -> b)
-> (b -> a)
-> TypeInformation a
-> TypeInformation b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Either String b) -> (a -> b) -> a -> Either String b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either String b
forall (f :: * -> *) a. Applicative f => a -> f a
pure
parseTypeInformation :: ()
  => (a -> Either String b) -> (b -> a)
  -> TypeInformation a -> TypeInformation b
parseTypeInformation :: (a -> Either String b)
-> (b -> a) -> TypeInformation a -> TypeInformation b
parseTypeInformation a -> Either String b
to b -> a
from TypeInformation {a -> PrimExpr
encode :: a -> PrimExpr
encode :: forall a. TypeInformation a -> a -> PrimExpr
encode, Value a
decode :: Value a
decode :: forall a. TypeInformation a -> Value a
decode, String
typeName :: String
typeName :: forall a. TypeInformation a -> String
typeName} =
  TypeInformation :: forall a. (a -> PrimExpr) -> Value a -> String -> TypeInformation a
TypeInformation
    { encode :: b -> PrimExpr
encode = a -> PrimExpr
encode (a -> PrimExpr) -> (b -> a) -> b -> PrimExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a
from
    , decode :: Value b
decode = (a -> Either Text b) -> Value a -> Value b
forall a b. (a -> Either Text b) -> Value a -> Value b
Hasql.refine ((String -> Text) -> Either String b -> Either Text b
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first String -> Text
Text.pack (Either String b -> Either Text b)
-> (a -> Either String b) -> a -> Either Text b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Either String b
to) Value a
decode
    , String
typeName :: String
typeName :: String
typeName
    }