{-# 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
  { forall a. OneRow a -> a
getOneRow :: a
  }
  deriving stock (Int -> OneRow a -> ShowS
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
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 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 = forall a. a -> OneRow a
OneRow forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Row a -> Result a
D.singleRow forall a. DecodeRow a => Row a
decodeRow