Skip to content

Commit

Permalink
Merge pull request #28 from haskell-works/newhoggy/simplified-record-…
Browse files Browse the repository at this point in the history
…decoding-2

New ToSqlParameters type class
  • Loading branch information
newhoggy authored Nov 15, 2024
2 parents fabec3d + 619c38a commit 1fddd42
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 2 additions & 0 deletions rds-data.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ library codecs
Data.RdsData.Encode.Param
Data.RdsData.Encode.Params
Data.RdsData.Encode.Row
Data.RdsData.Encode.ToSqlParameters
Data.RdsData.Encode.Value
Data.RdsData.Internal.Aeson
Data.RdsData.Internal.Convert
Expand All @@ -134,6 +135,7 @@ library codecs
Data.RdsData.Orphans
Data.RdsData.Types
Data.RdsData.Types.Array
Data.RdsData.Types.EncodedParams
Data.RdsData.Types.Param
Data.RdsData.Types.Value
other-modules: Paths_rds_data
Expand Down
13 changes: 1 addition & 12 deletions src/Data/RdsData/Encode/Params.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import Data.Functor.Contravariant.Divisible
import Data.Int
import Data.RdsData.Encode.Array (EncodeArray (..))
import Data.RdsData.Encode.Param (EncodeParam (..))
import Data.RdsData.Types.EncodedParams
import Data.RdsData.Types.Param
import Data.Text (Text)
import Data.Time
Expand All @@ -66,18 +67,6 @@ import qualified Data.RdsData.Encode.Param as EP
import qualified Data.Text.Lazy as LT
import qualified Prelude as P

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

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

instance Monoid EncodedParams where
mempty =
EncodedParams id

newtype EncodeParams a = EncodeParams
{ run :: a -> [Param] -> [Param]
}
Expand Down
18 changes: 18 additions & 0 deletions src/Data/RdsData/Encode/ToSqlParameters.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Data.RdsData.Encode.ToSqlParameters
( ToSqlParameters(..)
) where

import Data.RdsData.Encode.Params
import Data.RdsData.Types.Param

import qualified Amazonka.RDSData as AWS

class ToSqlParameters a where
toSqlParameters :: a -> [AWS.SqlParameter]

instance ToSqlParameters [AWS.SqlParameter] where
toSqlParameters = id

instance ToSqlParameters EncodedParams where
toSqlParameters encodedParams =
fmap toSqlParameter (encodedParams.run [])
17 changes: 17 additions & 0 deletions src/Data/RdsData/Types/EncodedParams.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Data.RdsData.Types.EncodedParams
( EncodedParams(..)
) where

import Data.RdsData.Types.Param

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

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

instance Monoid EncodedParams where
mempty =
EncodedParams id

0 comments on commit 1fddd42

Please sign in to comment.