@@ -106,15 +106,12 @@ filterArguments = filter isPresented where
106106postgresT :: String -> Type
107107postgresT t = AppT (ConT ''PostgresType) (LitT (StrTyLit t))
108108
109- -- | Example: ''FromField "varchar" True a -> [PostgresType "varchar" ~ a, FromField (Maybe a) ]
110- mkContextT :: Name -> String -> Bool -> Name -> [Type ]
111- mkContextT constraint typelit nullable name = [
109+ -- | Example: ''FromField "varchar" a -> [PostgresType "varchar" ~ a, FromField a ]
110+ mkContextT :: Name -> String -> Name -> [Type ]
111+ mkContextT constraint typelit name = [
112112 EqualityT `AppT ` (postgresT typelit) `AppT ` (VarT name)
113- , (ConT constraint) `AppT ` result
114- ] where
115- result = case nullable of
116- False -> VarT name
117- True -> (ConT ''Maybe) `AppT ` (VarT name)
113+ , (ConT constraint) `AppT ` VarT name
114+ ]
118115
119116-- | Examples:
120117-- (PGSingle "varchar") -> (["y"], [PostgresType "varchar" ~ y, FromField y], y)
@@ -126,24 +123,27 @@ mkContextT constraint typelit nullable name = [
126123mkResultT :: PostgresBindOptions -> String -> PGResult -> Q ([Name ], [Type ], Type )
127124mkResultT _ _ (PGSingle t) = do
128125 name <- newName " y"
129- return ([name], mkContextT ''FromField t False name, VarT name)
126+ return ([name], mkContextT ''FromField t name, VarT name)
130127
131128mkResultT (PostgresBindOptions {.. }) _fname (PGSetOf tname) = do
132129 name <- newName " y"
133130 let constraint = case (pboSetOfReturnType tname) of
134131 AsRow -> ''FromRow
135132 AsField -> ''FromField
136- return ([name], mkContextT constraint tname False name, ListT `AppT ` (VarT name))
133+ return ([name], mkContextT constraint tname name, ListT `AppT ` (VarT name))
137134
138135mkResultT (PostgresBindOptions {.. }) fname (PGTable cs) = do
139136 names <- sequence $ replicate (length cs) (newName " y" )
140- let context = concat $ zipWith3
141- (\ (PGColumn _ typelit) name nullable -> mkContextT ''FromField typelit nullable name)
142- cs
143- names
144- (map (pboIsNullable fname . (\ (PGColumn _name ctype) -> ctype)) cs)
137+ let context = concat $
138+ zipWith (\ (PGColumn _ typelit) name -> mkContextT ''FromField typelit name) cs names
139+
140+ let wrapColumn (PGColumn cname _ctype) = case pboIsNullable fname cname of
141+ True -> AppT (ConT ''Maybe)
142+ False -> id
143+
144+ let clause = AppT ListT $ foldl AppT (TupleT (length cs)) $
145+ zipWith wrapColumn cs (map VarT names)
145146
146- let clause = AppT ListT $ foldl AppT (TupleT (length cs)) $ map VarT names
147147 return (names, context, clause)
148148
149149-- | Example: [PGArgument "x" "varchar" True, PGArgument "y" "bigint" False] -> (
@@ -153,7 +153,7 @@ mkResultT (PostgresBindOptions {..}) fname (PGTable cs) = do
153153mkArgsT :: [PGArgument ] -> Q ([Name ], [Type ], [Type ])
154154mkArgsT cs = do
155155 names <- sequence $ replicate (length cs) (newName " x" )
156- let context = concat $ zipWith (\ (PGArgument _ t _) n -> mkContextT ''ToField t False n) cs names
156+ let context = concat $ zipWith (\ (PGArgument _ t _) n -> mkContextT ''ToField t n) cs names
157157
158158 let defWrap d = case d of
159159 True -> AppT (ConT ''Maybe)
0 commit comments