Skip to content

Commit

Permalink
Merge pull request #24 from haskell-works/newhoggy/support-for-named-…
Browse files Browse the repository at this point in the history
…parameters

Support for named parameters
  • Loading branch information
newhoggy authored Oct 19, 2024
2 parents 85de1b5 + 43d22fe commit 70f4602
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Data/RdsData/Encode/Params.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

module Data.RdsData.Encode.Params
( EncodeParams(..)
, EncodedParams(..)
, encode

, rdsValue

, column

, maybe
, named

, array
, bool
Expand Down Expand Up @@ -62,10 +65,26 @@ import qualified Data.RdsData.Encode.Param as EP
import qualified Data.Text.Lazy as LT
import qualified Prelude as P

newtype EncodedParams = EncodedParams
{ unEncodedParams :: [Param] -> [Param]
}

instance Semigroup EncodedParams where
EncodedParams f <> EncodedParams g =
EncodedParams (f . g)

instance Monoid EncodedParams where
mempty =
EncodedParams id

newtype EncodeParams a = EncodeParams
{ encodeParams :: a -> [Param] -> [Param]
}

encode :: EncodeParams a -> a -> EncodedParams
encode (EncodeParams f) a =
EncodedParams (f a)

instance Contravariant EncodeParams where
contramap f (EncodeParams g) =
EncodeParams (g . f)
Expand Down Expand Up @@ -99,6 +118,11 @@ column :: EncodeParam a -> EncodeParams a
column (EncodeParam f) =
EncodeParams \a -> (f a:)

named :: Text -> EncodeParam a -> EncodeParams a
named n ep =
EncodeParams \a ->
(EP.encodeParam (EP.named n ep) a:)

--------------------------------------------------------------------------------

maybe :: EncodeParams a -> EncodeParams (Maybe a)
Expand Down

0 comments on commit 70f4602

Please sign in to comment.