{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
module Hasql.Interpolate.Internal.Encoder
( EncodeValue (..),
EncodeField (..),
)
where
import Data.ByteString (ByteString)
import Data.ByteString.Lazy (LazyByteString)
import Data.ByteString.Lazy qualified as ByteString.Lazy
import Data.Functor.Contravariant (contramap)
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 = NullableOrNot Value a -> Value [a]
forall (foldable :: * -> *) element.
Foldable foldable =>
NullableOrNot Value element -> Value (foldable element)
foldableArray NullableOrNot Value a
forall a. EncodeField a => NullableOrNot Value a
encodeField
instance EncodeField a => EncodeValue (Vector a) where
encodeValue :: Value (Vector a)
encodeValue = NullableOrNot Value a -> Value (Vector a)
forall (foldable :: * -> *) element.
Foldable foldable =>
NullableOrNot Value element -> Value (foldable element)
foldableArray NullableOrNot Value a
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
instance EncodeValue ByteString where
encodeValue :: Value ByteString
encodeValue = Value ByteString
bytea
instance EncodeValue LazyByteString where
encodeValue :: Value LazyByteString
encodeValue = (LazyByteString -> ByteString)
-> Value ByteString -> Value LazyByteString
forall a' a. (a' -> a) -> Value a -> Value a'
forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap LazyByteString -> ByteString
ByteString.Lazy.toStrict Value ByteString
bytea
class EncodeField a where
encodeField :: NullableOrNot Value a
instance {-# OVERLAPPABLE #-} EncodeValue a => EncodeField a where
encodeField :: NullableOrNot Value a
encodeField = Value a -> NullableOrNot Value a
forall (encoder :: * -> *) a. encoder a -> NullableOrNot encoder a
nonNullable Value a
forall a. EncodeValue a => Value a
encodeValue
instance EncodeValue a => EncodeField (Maybe a) where
encodeField :: NullableOrNot Value (Maybe a)
encodeField = Value a -> NullableOrNot Value (Maybe a)
forall (encoder :: * -> *) a.
encoder a -> NullableOrNot encoder (Maybe a)
nullable Value a
forall a. EncodeValue a => Value a
encodeValue