{-# OPTIONS_HADDOCK not-home #-}

{-# LANGUAGE DataKinds #-}

module Opaleye.Internal.Constant where

import           Opaleye.Field                   (Field)
import qualified Opaleye.Field                   as F
import qualified Opaleye.SqlTypes                 as T

import qualified Data.Aeson                      as Ae
import qualified Data.CaseInsensitive            as CI
import qualified Data.Int                        as Int
import qualified Data.Text                       as ST
import qualified Data.Text.Lazy                  as LT
import qualified Data.ByteString                 as SBS
import qualified Data.ByteString.Lazy            as LBS
import qualified Data.Scientific                 as Sci
import qualified Data.Time.Compat                as Time
import qualified Data.UUID                       as UUID

import qualified Data.Profunctor.Product         as PP
import           Data.Profunctor.Product         (empty, (***!), (+++!))
import qualified Data.Profunctor.Product.Default as D
import qualified Data.Profunctor                 as P

import qualified Database.PostgreSQL.Simple.Range as R
import           Database.PostgreSQL.Simple.Newtypes ( Aeson, getAeson )

toFields :: D.Default ToFields haskells fields
         => haskells -> fields
toFields :: forall haskells fields.
Default ToFields haskells fields =>
haskells -> fields
toFields = ToFields haskells fields -> haskells -> fields
forall haskells fields.
ToFields haskells fields -> haskells -> fields
constantExplicit ToFields haskells fields
forall (p :: * -> * -> *) a b. Default p a b => p a b
D.def

-- | A way of turning Haskell values of type @haskells@ into SQL
-- fields.  Use it with 'Opaleye.ToFields.toFields'.
newtype ToFields haskells fields =
  ToFields { forall haskells fields.
ToFields haskells fields -> haskells -> fields
constantExplicit :: haskells -> fields }

instance D.Default ToFields haskell (F.Field sql)
         => D.Default ToFields (Maybe haskell) (F.FieldNullable sql) where
  def :: ToFields (Maybe haskell) (FieldNullable sql)
def = (Maybe haskell -> FieldNullable sql)
-> ToFields (Maybe haskell) (FieldNullable sql)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields (Maybe (Field sql) -> FieldNullable sql
forall a. Maybe (Field a) -> FieldNullable a
F.maybeToNullable (Maybe (Field sql) -> FieldNullable sql)
-> (Maybe haskell -> Maybe (Field sql))
-> Maybe haskell
-> FieldNullable sql
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (haskell -> Field sql) -> Maybe haskell -> Maybe (Field sql)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap haskell -> Field sql
f)
    where ToFields haskell -> Field sql
f = ToFields haskell (Field sql)
forall (p :: * -> * -> *) a b. Default p a b => p a b
D.def

toToFields :: (haskells -> fields) -> ToFields haskells fields
toToFields :: forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields = (haskells -> fields) -> ToFields haskells fields
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields

instance D.Default ToFields (Field a) (Field a) where
  def :: ToFields (Field a) (Field a)
def = (Field a -> Field a) -> ToFields (Field a) (Field a)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Field a -> Field a
forall a. a -> a
id

instance D.Default ToFields String (Field T.SqlText) where
  def :: ToFields String (Field SqlText)
def = (String -> Field SqlText) -> ToFields String (Field SqlText)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields String -> Field SqlText
T.sqlString

instance D.Default ToFields LBS.ByteString (Field T.SqlBytea) where
  def :: ToFields ByteString (Field SqlBytea)
def = (ByteString -> Field SqlBytea)
-> ToFields ByteString (Field SqlBytea)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ByteString -> Field SqlBytea
T.sqlLazyByteString

instance D.Default ToFields SBS.ByteString (Field T.SqlBytea) where
  def :: ToFields ByteString (Field SqlBytea)
def = (ByteString -> Field SqlBytea)
-> ToFields ByteString (Field SqlBytea)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ByteString -> Field SqlBytea
T.sqlStrictByteString

instance D.Default ToFields ST.Text (Field T.SqlText) where
  def :: ToFields Text (Field SqlText)
def = (Text -> Field SqlText) -> ToFields Text (Field SqlText)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Text -> Field SqlText
T.sqlStrictText

instance D.Default ToFields LT.Text (Field T.SqlText) where
  def :: ToFields Text (Field SqlText)
def = (Text -> Field SqlText) -> ToFields Text (Field SqlText)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Text -> Field SqlText
T.sqlLazyText

instance D.Default ToFields String (Field T.SqlVarcharN) where
  def :: ToFields String (Field SqlVarcharN)
def = (String -> Field SqlVarcharN)
-> ToFields String (Field SqlVarcharN)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields String -> Field SqlVarcharN
T.sqlStringVarcharN

instance D.Default ToFields ST.Text (Field T.SqlVarcharN) where
  def :: ToFields Text (Field SqlVarcharN)
def = (Text -> Field SqlVarcharN) -> ToFields Text (Field SqlVarcharN)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Text -> Field SqlVarcharN
T.sqlStrictTextVarcharN

instance D.Default ToFields LT.Text (Field T.SqlVarcharN) where
  def :: ToFields Text (Field SqlVarcharN)
def = (Text -> Field SqlVarcharN) -> ToFields Text (Field SqlVarcharN)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Text -> Field SqlVarcharN
T.sqlLazyTextVarcharN

instance D.Default ToFields Sci.Scientific (Field T.SqlNumeric) where
  def :: ToFields Scientific (Field SqlNumeric)
def = (Scientific -> Field SqlNumeric)
-> ToFields Scientific (Field SqlNumeric)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Scientific -> Field SqlNumeric
T.sqlNumeric

instance D.Default ToFields Int (Field T.SqlInt4) where
  def :: ToFields Int (Field SqlInt4)
def = (Int -> Field SqlInt4) -> ToFields Int (Field SqlInt4)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Int -> Field SqlInt4
T.sqlInt4

instance D.Default ToFields Int.Int32 (Field T.SqlInt4) where
  def :: ToFields Int32 (Field SqlInt4)
def = (Int32 -> Field SqlInt4) -> ToFields Int32 (Field SqlInt4)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((Int32 -> Field SqlInt4) -> ToFields Int32 (Field SqlInt4))
-> (Int32 -> Field SqlInt4) -> ToFields Int32 (Field SqlInt4)
forall a b. (a -> b) -> a -> b
$ Int -> Field SqlInt4
T.sqlInt4 (Int -> Field SqlInt4) -> (Int32 -> Int) -> Int32 -> Field SqlInt4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral

instance D.Default ToFields Int.Int64 (Field T.SqlInt8) where
  def :: ToFields Int64 (Field SqlInt8)
def = (Int64 -> Field SqlInt8) -> ToFields Int64 (Field SqlInt8)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Int64 -> Field SqlInt8
T.sqlInt8

instance D.Default ToFields Double (Field T.SqlFloat8) where
  def :: ToFields Double (Field SqlFloat8)
def = (Double -> Field SqlFloat8) -> ToFields Double (Field SqlFloat8)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Double -> Field SqlFloat8
T.sqlDouble

instance D.Default ToFields Bool (Field T.SqlBool) where
  def :: ToFields Bool (Field SqlBool)
def = (Bool -> Field SqlBool) -> ToFields Bool (Field SqlBool)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Bool -> Field SqlBool
T.sqlBool

instance D.Default ToFields UUID.UUID (Field T.SqlUuid) where
  def :: ToFields UUID (Field SqlUuid)
def = (UUID -> Field SqlUuid) -> ToFields UUID (Field SqlUuid)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields UUID -> Field SqlUuid
T.sqlUUID

instance D.Default ToFields Time.Day (Field T.SqlDate) where
  def :: ToFields Day (Field SqlDate)
def = (Day -> Field SqlDate) -> ToFields Day (Field SqlDate)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Day -> Field SqlDate
T.sqlDay

instance D.Default ToFields Time.UTCTime (Field T.SqlTimestamptz) where
  def :: ToFields UTCTime (Field SqlTimestamptz)
def = (UTCTime -> Field SqlTimestamptz)
-> ToFields UTCTime (Field SqlTimestamptz)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields UTCTime -> Field SqlTimestamptz
T.sqlUTCTime

instance D.Default ToFields Time.LocalTime (Field T.SqlTimestamp) where
  def :: ToFields LocalTime (Field SqlTimestamp)
def = (LocalTime -> Field SqlTimestamp)
-> ToFields LocalTime (Field SqlTimestamp)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields LocalTime -> Field SqlTimestamp
T.sqlLocalTime

instance D.Default ToFields Time.ZonedTime (Field T.SqlTimestamptz) where
  def :: ToFields ZonedTime (Field SqlTimestamptz)
def = (ZonedTime -> Field SqlTimestamptz)
-> ToFields ZonedTime (Field SqlTimestamptz)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ZonedTime -> Field SqlTimestamptz
T.sqlZonedTime

instance D.Default ToFields Time.TimeOfDay (Field T.SqlTime) where
  def :: ToFields TimeOfDay (Field SqlTime)
def = (TimeOfDay -> Field SqlTime) -> ToFields TimeOfDay (Field SqlTime)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields TimeOfDay -> Field SqlTime
T.sqlTimeOfDay

instance D.Default ToFields Time.CalendarDiffTime (Field T.SqlInterval) where
  def :: ToFields CalendarDiffTime (Field SqlInterval)
def = (CalendarDiffTime -> Field SqlInterval)
-> ToFields CalendarDiffTime (Field SqlInterval)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields CalendarDiffTime -> Field SqlInterval
T.sqlInterval

instance D.Default ToFields (CI.CI ST.Text) (Field T.SqlCitext) where
  def :: ToFields (CI Text) (Field SqlCitext)
def = (CI Text -> Field SqlCitext)
-> ToFields (CI Text) (Field SqlCitext)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields CI Text -> Field SqlCitext
T.sqlCiStrictText

instance D.Default ToFields (CI.CI LT.Text) (Field T.SqlCitext) where
  def :: ToFields (CI Text) (Field SqlCitext)
def = (CI Text -> Field SqlCitext)
-> ToFields (CI Text) (Field SqlCitext)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields CI Text -> Field SqlCitext
T.sqlCiLazyText

instance D.Default ToFields SBS.ByteString (Field T.SqlJson) where
  def :: ToFields ByteString (Field SqlJson)
def = (ByteString -> Field SqlJson)
-> ToFields ByteString (Field SqlJson)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ByteString -> Field SqlJson
T.sqlStrictJSON

instance D.Default ToFields LBS.ByteString (Field T.SqlJson) where
  def :: ToFields ByteString (Field SqlJson)
def = (ByteString -> Field SqlJson)
-> ToFields ByteString (Field SqlJson)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ByteString -> Field SqlJson
T.sqlLazyJSON

instance D.Default ToFields Ae.Value (Field T.SqlJson) where
  def :: ToFields Value (Field SqlJson)
def = (Value -> Field SqlJson) -> ToFields Value (Field SqlJson)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Value -> Field SqlJson
forall a. ToJSON a => a -> Field SqlJson
T.sqlValueJSON

instance D.Default ToFields SBS.ByteString (Field T.SqlJsonb) where
  def :: ToFields ByteString (Field SqlJsonb)
def = (ByteString -> Field SqlJsonb)
-> ToFields ByteString (Field SqlJsonb)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ByteString -> Field SqlJsonb
T.sqlStrictJSONB

instance D.Default ToFields LBS.ByteString (Field T.SqlJsonb) where
  def :: ToFields ByteString (Field SqlJsonb)
def = (ByteString -> Field SqlJsonb)
-> ToFields ByteString (Field SqlJsonb)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ByteString -> Field SqlJsonb
T.sqlLazyJSONB

instance (Ae.ToJSON a) => D.Default ToFields (Aeson a) (Field T.SqlJson) where
  def :: ToFields (Aeson a) (Field SqlJson)
def = (Aeson a -> Field SqlJson) -> ToFields (Aeson a) (Field SqlJson)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((Aeson a -> Field SqlJson) -> ToFields (Aeson a) (Field SqlJson))
-> (Aeson a -> Field SqlJson) -> ToFields (Aeson a) (Field SqlJson)
forall a b. (a -> b) -> a -> b
$ a -> Field SqlJson
forall a. ToJSON a => a -> Field SqlJson
T.sqlValueJSON (a -> Field SqlJson) -> (Aeson a -> a) -> Aeson a -> Field SqlJson
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Aeson a -> a
forall a. Aeson a -> a
getAeson

instance D.Default ToFields Ae.Value (Field T.SqlJsonb) where
  def :: ToFields Value (Field SqlJsonb)
def = (Value -> Field SqlJsonb) -> ToFields Value (Field SqlJsonb)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields Value -> Field SqlJsonb
forall a. ToJSON a => a -> Field SqlJsonb
T.sqlValueJSONB

instance D.Default ToFields haskell (F.Field_ n sql) => D.Default ToFields (Maybe haskell) (Maybe (F.Field_ n sql)) where
  def :: ToFields (Maybe haskell) (Maybe (Field_ n sql))
def = (Maybe haskell -> Maybe (Field_ n sql))
-> ToFields (Maybe haskell) (Maybe (Field_ n sql))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields (haskell -> Field_ n sql
forall haskells fields.
Default ToFields haskells fields =>
haskells -> fields
toFields (haskell -> Field_ n sql) -> Maybe haskell -> Maybe (Field_ n sql)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)

instance (Ae.ToJSON a) => D.Default ToFields (Aeson a) (F.Field T.SqlJsonb) where
  def :: ToFields (Aeson a) (Field SqlJsonb)
def = (Aeson a -> Field SqlJsonb) -> ToFields (Aeson a) (Field SqlJsonb)
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((Aeson a -> Field SqlJsonb)
 -> ToFields (Aeson a) (Field SqlJsonb))
-> (Aeson a -> Field SqlJsonb)
-> ToFields (Aeson a) (Field SqlJsonb)
forall a b. (a -> b) -> a -> b
$ a -> Field SqlJsonb
forall a. ToJSON a => a -> Field SqlJsonb
T.sqlValueJSONB (a -> Field SqlJsonb)
-> (Aeson a -> a) -> Aeson a -> Field SqlJsonb
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Aeson a -> a
forall a. Aeson a -> a
getAeson

instance (D.Default ToFields a (F.Field_ n b), T.IsSqlType b)
         => D.Default ToFields [a] (F.Field (T.SqlArray_ n b)) where
  def :: ToFields [a] (Field (SqlArray_ n b))
def = ([a] -> Field (SqlArray_ n b))
-> ToFields [a] (Field (SqlArray_ n b))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((a -> Field_ n b) -> [a] -> Field (SqlArray_ n b)
forall b a (n :: Nullability).
IsSqlType b =>
(a -> Field_ n b) -> [a] -> Field (SqlArray_ n b)
T.sqlArray (ToFields a (Field_ n b) -> a -> Field_ n b
forall haskells fields.
ToFields haskells fields -> haskells -> fields
constantExplicit ToFields a (Field_ n b)
forall (p :: * -> * -> *) a b. Default p a b => p a b
D.def))

instance D.Default ToFields (R.PGRange Int.Int) (F.Field (T.SqlRange T.SqlInt4)) where
  def :: ToFields (PGRange Int) (Field (SqlRange SqlInt4))
def = (PGRange Int -> Field (SqlRange SqlInt4))
-> ToFields (PGRange Int) (Field (SqlRange SqlInt4))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((PGRange Int -> Field (SqlRange SqlInt4))
 -> ToFields (PGRange Int) (Field (SqlRange SqlInt4)))
-> (PGRange Int -> Field (SqlRange SqlInt4))
-> ToFields (PGRange Int) (Field (SqlRange SqlInt4))
forall a b. (a -> b) -> a -> b
$ \(R.PGRange RangeBound Int
a RangeBound Int
b) -> (Int -> Field SqlInt4)
-> RangeBound Int -> RangeBound Int -> Field (SqlRange SqlInt4)
forall b a.
IsRangeType b =>
(a -> Field b)
-> RangeBound a -> RangeBound a -> Field (SqlRange b)
T.sqlRange Int -> Field SqlInt4
T.sqlInt4 RangeBound Int
a RangeBound Int
b

instance D.Default ToFields (R.PGRange Int.Int64) (F.Field (T.SqlRange T.SqlInt8)) where
  def :: ToFields (PGRange Int64) (Field (SqlRange SqlInt8))
def = (PGRange Int64 -> Field (SqlRange SqlInt8))
-> ToFields (PGRange Int64) (Field (SqlRange SqlInt8))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((PGRange Int64 -> Field (SqlRange SqlInt8))
 -> ToFields (PGRange Int64) (Field (SqlRange SqlInt8)))
-> (PGRange Int64 -> Field (SqlRange SqlInt8))
-> ToFields (PGRange Int64) (Field (SqlRange SqlInt8))
forall a b. (a -> b) -> a -> b
$ \(R.PGRange RangeBound Int64
a RangeBound Int64
b) -> (Int64 -> Field SqlInt8)
-> RangeBound Int64 -> RangeBound Int64 -> Field (SqlRange SqlInt8)
forall b a.
IsRangeType b =>
(a -> Field b)
-> RangeBound a -> RangeBound a -> Field (SqlRange b)
T.sqlRange Int64 -> Field SqlInt8
T.sqlInt8 RangeBound Int64
a RangeBound Int64
b

instance D.Default ToFields (R.PGRange Sci.Scientific) (F.Field (T.SqlRange T.SqlNumeric)) where
  def :: ToFields (PGRange Scientific) (Field (SqlRange SqlNumeric))
def = (PGRange Scientific -> Field (SqlRange SqlNumeric))
-> ToFields (PGRange Scientific) (Field (SqlRange SqlNumeric))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((PGRange Scientific -> Field (SqlRange SqlNumeric))
 -> ToFields (PGRange Scientific) (Field (SqlRange SqlNumeric)))
-> (PGRange Scientific -> Field (SqlRange SqlNumeric))
-> ToFields (PGRange Scientific) (Field (SqlRange SqlNumeric))
forall a b. (a -> b) -> a -> b
$ \(R.PGRange RangeBound Scientific
a RangeBound Scientific
b) -> (Scientific -> Field SqlNumeric)
-> RangeBound Scientific
-> RangeBound Scientific
-> Field (SqlRange SqlNumeric)
forall b a.
IsRangeType b =>
(a -> Field b)
-> RangeBound a -> RangeBound a -> Field (SqlRange b)
T.sqlRange Scientific -> Field SqlNumeric
T.sqlNumeric RangeBound Scientific
a RangeBound Scientific
b

instance D.Default ToFields (R.PGRange Time.LocalTime) (F.Field (T.SqlRange T.SqlTimestamp)) where
  def :: ToFields (PGRange LocalTime) (Field (SqlRange SqlTimestamp))
def = (PGRange LocalTime -> Field (SqlRange SqlTimestamp))
-> ToFields (PGRange LocalTime) (Field (SqlRange SqlTimestamp))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((PGRange LocalTime -> Field (SqlRange SqlTimestamp))
 -> ToFields (PGRange LocalTime) (Field (SqlRange SqlTimestamp)))
-> (PGRange LocalTime -> Field (SqlRange SqlTimestamp))
-> ToFields (PGRange LocalTime) (Field (SqlRange SqlTimestamp))
forall a b. (a -> b) -> a -> b
$ \(R.PGRange RangeBound LocalTime
a RangeBound LocalTime
b) -> (LocalTime -> Field SqlTimestamp)
-> RangeBound LocalTime
-> RangeBound LocalTime
-> Field (SqlRange SqlTimestamp)
forall b a.
IsRangeType b =>
(a -> Field b)
-> RangeBound a -> RangeBound a -> Field (SqlRange b)
T.sqlRange LocalTime -> Field SqlTimestamp
T.sqlLocalTime RangeBound LocalTime
a RangeBound LocalTime
b

instance D.Default ToFields (R.PGRange Time.UTCTime) (F.Field (T.SqlRange T.SqlTimestamptz)) where
  def :: ToFields (PGRange UTCTime) (Field (SqlRange SqlTimestamptz))
def = (PGRange UTCTime -> Field (SqlRange SqlTimestamptz))
-> ToFields (PGRange UTCTime) (Field (SqlRange SqlTimestamptz))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((PGRange UTCTime -> Field (SqlRange SqlTimestamptz))
 -> ToFields (PGRange UTCTime) (Field (SqlRange SqlTimestamptz)))
-> (PGRange UTCTime -> Field (SqlRange SqlTimestamptz))
-> ToFields (PGRange UTCTime) (Field (SqlRange SqlTimestamptz))
forall a b. (a -> b) -> a -> b
$ \(R.PGRange RangeBound UTCTime
a RangeBound UTCTime
b) -> (UTCTime -> Field SqlTimestamptz)
-> RangeBound UTCTime
-> RangeBound UTCTime
-> Field (SqlRange SqlTimestamptz)
forall b a.
IsRangeType b =>
(a -> Field b)
-> RangeBound a -> RangeBound a -> Field (SqlRange b)
T.sqlRange UTCTime -> Field SqlTimestamptz
T.sqlUTCTime RangeBound UTCTime
a RangeBound UTCTime
b

instance D.Default ToFields (R.PGRange Time.Day) (F.Field (T.SqlRange T.SqlDate)) where
  def :: ToFields (PGRange Day) (Field (SqlRange SqlDate))
def = (PGRange Day -> Field (SqlRange SqlDate))
-> ToFields (PGRange Day) (Field (SqlRange SqlDate))
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
toToFields ((PGRange Day -> Field (SqlRange SqlDate))
 -> ToFields (PGRange Day) (Field (SqlRange SqlDate)))
-> (PGRange Day -> Field (SqlRange SqlDate))
-> ToFields (PGRange Day) (Field (SqlRange SqlDate))
forall a b. (a -> b) -> a -> b
$ \(R.PGRange RangeBound Day
a RangeBound Day
b) -> (Day -> Field SqlDate)
-> RangeBound Day -> RangeBound Day -> Field (SqlRange SqlDate)
forall b a.
IsRangeType b =>
(a -> Field b)
-> RangeBound a -> RangeBound a -> Field (SqlRange b)
T.sqlRange Day -> Field SqlDate
T.sqlDay RangeBound Day
a RangeBound Day
b

-- { Boilerplate instances

instance Functor (ToFields a) where
  fmap :: forall a b. (a -> b) -> ToFields a a -> ToFields a b
fmap a -> b
f (ToFields a -> a
g) = (a -> b) -> ToFields a b
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields ((a -> b) -> (a -> a) -> a -> b
forall a b. (a -> b) -> (a -> a) -> a -> b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f a -> a
g)

instance Applicative (ToFields a) where
  pure :: forall a. a -> ToFields a a
pure = (a -> a) -> ToFields a a
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields ((a -> a) -> ToFields a a) -> (a -> a -> a) -> a -> ToFields a a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> a
forall a. a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
  ToFields a -> a -> b
f <*> :: forall a b. ToFields a (a -> b) -> ToFields a a -> ToFields a b
<*> ToFields a -> a
x = (a -> b) -> ToFields a b
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields (a -> a -> b
f (a -> a -> b) -> (a -> a) -> a -> b
forall a b. (a -> a -> b) -> (a -> a) -> a -> b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> a
x)

instance P.Profunctor ToFields where
  dimap :: forall a b c d.
(a -> b) -> (c -> d) -> ToFields b c -> ToFields a d
dimap a -> b
f c -> d
g (ToFields b -> c
h) = (a -> d) -> ToFields a d
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields ((a -> b) -> (c -> d) -> (b -> c) -> a -> d
forall a b c d. (a -> b) -> (c -> d) -> (b -> c) -> a -> d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
P.dimap a -> b
f c -> d
g b -> c
h)

instance PP.ProductProfunctor ToFields where
  empty :: ToFields () ()
empty = (() -> ()) -> ToFields () ()
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields () -> ()
forall (p :: * -> * -> *). ProductProfunctor p => p () ()
empty
  ToFields a -> b
f ***! :: forall a b a' b'.
ToFields a b -> ToFields a' b' -> ToFields (a, a') (b, b')
***! ToFields a' -> b'
g = ((a, a') -> (b, b')) -> ToFields (a, a') (b, b')
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields (a -> b
f (a -> b) -> (a' -> b') -> (a, a') -> (b, b')
forall a b a' b'. (a -> b) -> (a' -> b') -> (a, a') -> (b, b')
forall (p :: * -> * -> *) a b a' b'.
ProductProfunctor p =>
p a b -> p a' b' -> p (a, a') (b, b')
***! a' -> b'
g)

instance PP.SumProfunctor ToFields where
  ToFields a -> b
f +++! :: forall a b a' b'.
ToFields a b
-> ToFields a' b' -> ToFields (Either a a') (Either b b')
+++! ToFields a' -> b'
g = (Either a a' -> Either b b')
-> ToFields (Either a a') (Either b b')
forall haskells fields.
(haskells -> fields) -> ToFields haskells fields
ToFields (a -> b
f (a -> b) -> (a' -> b') -> Either a a' -> Either b b'
forall a b a' b'.
(a -> b) -> (a' -> b') -> Either a a' -> Either b b'
forall (p :: * -> * -> *) a b a' b'.
SumProfunctor p =>
p a b -> p a' b' -> p (Either a a') (Either b b')
+++! a' -> b'
g)

-- }