Although I haven't fully understood yet, it seems that everything that
is obtained from the database with the runDB and get404 functions is
wrapped in a handler monad.
I need a value from the database which is of type Text, but I only managed to get the
Handler Text which is causing me a problem.
I'm probably complicated, but I'm a beginner, so I'm experimenting.
I have the following functions:
getCityFromMan :: Manifestation -> Handler Text --I want here to be just Text type
getCityFromMan man = do
loc <- runDB $ get404 $ manifestationLocation man --Manifestation has key to Location
ads <- runDB $ get404 $ locationAddress loc --Location has key to Address
let cityName = addressCity ads --Address has column city type Text
applyFilters :: ManFilter -> Manifestation -> Bool
applyFilters f man = and
[ go name filterSearch
, go city filterCity
go :: (z -> Bool) -> (ManFilter -> Maybe z) -> Bool
go x y =
case y f of
Nothing -> True
Just z -> x z
norm = T.filter validChar . T.map C.toLower . normalize NFKD
validChar = not . C.isMark
name x = norm x `T.isInfixOf` norm (manifestationName man) -- working ok
city' = getCityFromMan man --want to get name of city in Text type but its type is HandlerFor Text
city x = norm x == norm city' --get true if filter value and city is the same
I get error:
Couldn't match type ‘HandlerFor App Text’ with ‘Text’
Expected type: Text
Actual type: Handler Text
How to deal with this and is it even possible to extract Text from Handler Text?
On several similar problems I have seen that it is not possible, then what is the solution??
Thanks a lot, any advice is welcome.