I am trying to use Persistent with Yesod to get a list of all field keys from a table in my database. My access code is as follows:
getMapList :: Handler [Text]
getMapList = runDB $ do
dbList <- selectList [] []
return (map getMapName dbList)
where getMapName (Entity (Key (PersistText mapName)) _) = mapName
Please note that this is a game: "Map" is a map in the game sense, not in the Haskell sense.
I get the following error, which indicates that the type inference mechanism cannot determine my types, on the basis of which I use the database backing.
Handler/Create.hs:101:13:
Couldn't match type `PersistEntityBackend t0'
with `persistent-1.2.3.0:Database.Persist.Sql.Types.SqlBackend'
The type variable `t0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Expected type: PersistMonadBackend (SqlPersistT (HandlerT App IO))
Actual type: PersistEntityBackend t0
In a stmt of a 'do' block: dbList <- selectList [] []
In the second argument of `($)', namely
`do { dbList <- selectList [] [];
return (map getMapName dbList) }'
In the expression:
runDB
$ do { dbList <- selectList [] [];
return (map getMapName dbList) }
Does anyone know how to fix this? What do I need to add to the type signature in order to get this in order to validate the type correctly? Thanks!
EDIT: My model is defined as such:
GameMap
mapName Text
mapCode Text
UniqueGameMap mapName
deriving Typeable