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

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

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

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

-- | Parse the rows affected from the query result, as in an @insert@,
-- @update@, or @delete@ statement without a returning clause. ('D.rowsAffected')
instance DecodeResult RowsAffected where
  decodeResult :: Result RowsAffected
decodeResult = Int64 -> RowsAffected
RowsAffected forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Result Int64
D.rowsAffected