{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}

module Hasql.Interpolate.Internal.OneRow
  ( OneRow (..),
  )
where

import GHC.Generics (Generic)
import qualified Hasql.Decoders as D
import Hasql.Interpolate.Internal.Decoder

newtype OneRow a = OneRow
  { OneRow a -> a
getOneRow :: a
  }
  deriving stock (Int -> OneRow a -> ShowS
[OneRow a] -> ShowS
OneRow a -> String
(Int -> OneRow a -> ShowS)
-> (OneRow a -> String) -> ([OneRow a] -> ShowS) -> Show (OneRow a)
forall a. Show a => Int -> OneRow a -> ShowS
forall a. Show a => [OneRow a] -> ShowS
forall a. Show a => OneRow a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OneRow a] -> ShowS
$cshowList :: forall a. Show a => [OneRow a] -> ShowS
show :: OneRow a -> String
$cshow :: forall a. Show a => OneRow a -> String
showsPrec :: Int -> OneRow a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> OneRow a -> ShowS
Show, OneRow a -> OneRow a -> Bool
(OneRow a -> OneRow a -> Bool)
-> (OneRow a -> OneRow a -> Bool) -> Eq (OneRow a)
forall a. Eq a => OneRow a -> OneRow a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OneRow a -> OneRow a -> Bool
$c/= :: forall a. Eq a => OneRow a -> OneRow a -> Bool
== :: OneRow a -> OneRow a -> Bool
$c== :: forall a. Eq a => OneRow a -> OneRow a -> Bool
Eq, (forall x. OneRow a -> Rep (OneRow a) x)
-> (forall x. Rep (OneRow a) x -> OneRow a) -> Generic (OneRow a)
forall x. Rep (OneRow a) x -> OneRow a
forall x. OneRow a -> Rep (OneRow a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (OneRow a) x -> OneRow a
forall a x. OneRow a -> Rep (OneRow a) x
$cto :: forall a x. Rep (OneRow a) x -> OneRow a
$cfrom :: forall a x. OneRow a -> Rep (OneRow a) x
Generic)

-- | Parse a single row result, throw
-- 'Hasql.Errors.UnexpectedAmountOfRows'
-- otherwise. ('Hasql.Decoders.singleRow')
instance DecodeRow a => DecodeResult (OneRow a) where
  decodeResult :: Result (OneRow a)
decodeResult = a -> OneRow a
forall a. a -> OneRow a
OneRow (a -> OneRow a) -> Result a -> Result (OneRow a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Row a -> Result a
forall a. Row a -> Result a
D.singleRow Row a
forall a. DecodeRow a => Row a
decodeRow