1212{-# LANGUAGE TypeOperators #-}
1313{-# LANGUAGE ScopedTypeVariables #-}
1414{-# LANGUAGE FlexibleInstances #-}
15+ {-# LANGUAGE RecordWildCards #-}
1516
1617{-|
1718 Module: Database.PostgreSQL.Simple.Bind.Implementation
@@ -31,7 +32,7 @@ import Data.List (intersperse)
3132import Data.Text (Text )
3233import Database.PostgreSQL.Simple
3334import Database.PostgreSQL.Simple.Bind.Representation
34- import Database.PostgreSQL.Simple.Bind.Util (unwrapRow , unwrapColumn , mkFunctionName , Options (.. ))
35+ import Database.PostgreSQL.Simple.Bind.Common (unwrapRow , unwrapColumn , PostgresBindOptions (.. ))
3536import Database.PostgreSQL.Simple.FromField (FromField )
3637import Database.PostgreSQL.Simple.ToField
3738import Database.PostgreSQL.Simple.Types
@@ -45,7 +46,7 @@ type family PostgresType (a :: Symbol)
4546
4647
4748-- | Function that constructs binding for PostgreSQL stored function by it's signature.
48- bindFunction :: Options -> Text -> Q [Dec ]
49+ bindFunction :: PostgresBindOptions -> Text -> Q [Dec ]
4950bindFunction opt = (mkFunction opt) . parsePGFunction
5051
5152
@@ -79,7 +80,7 @@ filterArguments = filter isActual
7980
8081
8182
82- mkFunction :: Options -> PGFunction -> Q [Dec ]
83+ mkFunction :: PostgresBindOptions -> PGFunction -> Q [Dec ]
8384mkFunction opt f = sequence $ (($ f) . ($ opt)) <$> [mkFunctionT, mkFunctionE]
8485
8586postgresT :: String -> Type
@@ -121,8 +122,8 @@ mkArgsT cs = do
121122 return (names, context, clause)
122123
123124
124- mkFunctionT :: Options -> PGFunction -> Q Dec
125- mkFunctionT opt f@ (PGFunction _schema _name args ret) = do
125+ mkFunctionT :: PostgresBindOptions -> PGFunction -> Q Dec
126+ mkFunctionT ( PostgresBindOptions { .. }) f@ (PGFunction _schema _name args ret) = do
126127 (argNames, argContext, argClause) <- mkArgsT args
127128 (retNames, retContext, retClause) <- mkResultT ret
128129
@@ -132,7 +133,7 @@ mkFunctionT opt f@(PGFunction _schema _name args ret) = do
132133 let chain x = AppT (AppT ArrowT x)
133134 let clause = foldr1 chain $ (ConT ''Connection): (argClause ++ [AppT (ConT ''IO) retClause])
134135
135- return $ SigD (mkName (mkFunctionName opt f) ) $ ForallT vars context clause
136+ return $ SigD (mkName $ pboFunctionName f ) $ ForallT vars context clause
136137
137138
138139
@@ -162,14 +163,14 @@ unwrapE (PGSetOf _) q = (VarE 'fmap) `AppE` (VarE 'unwrapColumn) `AppE` q
162163unwrapE (PGTable _) q = q
163164
164165
165- mkFunctionE :: Options -> PGFunction -> Q Dec
166- mkFunctionE opt f@ (PGFunction _schema _name args ret) = do
166+ mkFunctionE :: PostgresBindOptions -> PGFunction -> Q Dec
167+ mkFunctionE ( PostgresBindOptions { .. }) f@ (PGFunction _schema _name args ret) = do
167168 names <- sequence $ replicate (length args) (newName " x" )
168169
169170 connName <- newName " conn"
170171 argsName <- newName " args"
171172
172- let funcName = mkName $ mkFunctionName opt f
173+ let funcName = mkName $ pboFunctionName f
173174
174175 let funcArgs = (VarP connName): (map VarP names)
175176
0 commit comments