Reputation: 308
I'm writing a REST API in Haskell with the Scotty framework. I have a persist table defined as
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User json
username Text
number Text
group Text Maybe
UniqueUsername username
UniqueNumber number
deriving(Show)
...
]
I then have a function to grab a user fetchUserByName :: Text -> IO (Entity User)
. What I'm not understanding is that if I have a variable user :: Entity User
, how do I access any of the fields, like username for this user? I feel like this should be completely trivial yet I can't seem to find the answer online. Or am I just going about this the wrong way? Thank you.
Upvotes: 3
Views: 350
Reputation: 12070
You can extract your User item using entityVal
, then you can to the desired column using the record name (which I believe is always generated to be of the format of the format
<tablename><columnname>
in camelcase)
print $ userGroup $ entityVal user
Upvotes: 4