yesod - Haskell/Persistent: Reusing "selectList" -
i trying write api in servant , writing lot of handlers this:
gettablea :: handler [arecord] gettablea = xs <- rundb (selectlist [] []) let records = map (\(entity _ v) -> v) xs return records gettableb :: handler [brecord] gettableb = xs <- rundb (selectlist [] []) let records = map (\(entity _ v) -> v) xs return records gettablec :: handler [crecord] gettablec = xs <- rundb (selectlist [] []) let records = map (\(entity _ v) -> v) xs return records
and on.
i want able have more like
gettable :: handler [a] gettable = xs <- rundb (selectlist [] []) let records = map (\(entity _ v) -> v) xs return records
however error
couldn't match expected type ‘sqlbackend’ actual type ‘persistentitybackend val’ relevant bindings include getall :: handler [val] (bound @ src/novation/handler.hs:101:1) in first argument of ‘rundb’, namely ‘(selectlist [] [])’ in stmt of 'do' block: xs <- rundb (selectlist [] []) in expression: { xs <- rundb (selectlist [] []); let records = map (\ (entity _ v) -> ...) xs; return records }
i hoping in end i'll able have this
server :: server myapi server = gettable :<|> gettable :<|> gettable type myapi = "tablea" :> '[json] [arecord] :<|> "tableb" :> '[json] [brecord] :<|> "tablec" :> '[json] [crecord]
instead of
server :: server myapi server = gettablea :<|> gettableb :<|> gettablec
Comments
Post a Comment