{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasql.Interpolate.Internal.Encoder
( EncodeValue (..),
EncodeField (..),
)
where
import Data.Int
import Data.Scientific (Scientific)
import Data.Text (Text)
import Data.Time (Day, DiffTime, LocalTime, UTCTime)
import Data.UUID (UUID)
import Data.Vector (Vector)
import Hasql.Encoders
class EncodeValue a where
encodeValue :: Value a
instance EncodeField a => EncodeValue [a] where
encodeValue :: Value [a]
encodeValue = forall (foldable :: * -> *) element.
Foldable foldable =>
NullableOrNot Value element -> Value (foldable element)
foldableArray forall a. EncodeField a => NullableOrNot Value a
encodeField
instance EncodeField a => EncodeValue (Vector a) where
encodeValue :: Value (Vector a)
encodeValue = forall (foldable :: * -> *) element.
Foldable foldable =>
NullableOrNot Value element -> Value (foldable element)
foldableArray forall a. EncodeField a => NullableOrNot Value a
encodeField
instance EncodeValue Bool where
encodeValue :: Value Bool
encodeValue = Value Bool
bool
instance EncodeValue Text where
encodeValue :: Value Text
encodeValue = Value Text
text
instance EncodeValue Int16 where
encodeValue :: Value Int16
encodeValue = Value Int16
int2
instance EncodeValue Int32 where
encodeValue :: Value Int32
encodeValue = Value Int32
int4
instance EncodeValue Int64 where
encodeValue :: Value Int64
encodeValue = Value Int64
int8
instance EncodeValue Float where
encodeValue :: Value Float
encodeValue = Value Float
float4
instance EncodeValue Double where
encodeValue :: Value Double
encodeValue = Value Double
float8
instance EncodeValue Char where
encodeValue :: Value Char
encodeValue = Value Char
char
instance EncodeValue Day where
encodeValue :: Value Day
encodeValue = Value Day
date
instance EncodeValue LocalTime where
encodeValue :: Value LocalTime
encodeValue = Value LocalTime
timestamp
instance EncodeValue UTCTime where
encodeValue :: Value UTCTime
encodeValue = Value UTCTime
timestamptz
instance EncodeValue Scientific where
encodeValue :: Value Scientific
encodeValue = Value Scientific
numeric
instance EncodeValue DiffTime where
encodeValue :: Value DiffTime
encodeValue = Value DiffTime
interval
instance EncodeValue UUID where
encodeValue :: Value UUID
encodeValue = Value UUID
uuid
class EncodeField a where
encodeField :: NullableOrNot Value a
instance {-# OVERLAPPABLE #-} EncodeValue a => EncodeField a where
encodeField :: NullableOrNot Value a
encodeField = forall (encoder :: * -> *) a. encoder a -> NullableOrNot encoder a
nonNullable forall a. EncodeValue a => Value a
encodeValue
instance EncodeValue a => EncodeField (Maybe a) where
encodeField :: NullableOrNot Value (Maybe a)
encodeField = forall (encoder :: * -> *) a.
encoder a -> NullableOrNot encoder (Maybe a)
nullable forall a. EncodeValue a => Value a
encodeValue