Dar*_*ver 10 haskell persistent yesod scotty
我使用Persistent orm和scotty web框架.
我希望通过id从db获取值.这些ID来自GET请求
有"获取"功能,它接受"密钥实体"变量并返回"可能实体".
我使用以下代码从db获取值
k <- keyFromValues $ [(PersistInt64 myOwnIntVarFromRequest)]
case k of
Left _ -> {-some processing-}
Right x -> do
t <- liftIO . runDb $ get (x::Key Post) --Post is one of my models
case t of
Nothing -> {-processing-}
Just x -> {-processing-}
Run Code Online (Sandbox Code Playgroud)
这些代码非常丑陋.但我不知道如何做得更好
所以我的问题是如何在不调用keyFromValues的情况下获取"Key Entity"类型的变量.
PS抱歉我的英语不好
| 归档时间: |
|
| 查看次数: |
1606 次 |
| 最近记录: |