2016-06-08 61 views
1

家伙我有点谟得到会话的用户ID,我需要从Session extrat用户的德ID。如何在(耶索德/哈斯克尔项目

我不能把它放在一个文本/诠释,因为它说,会议进行的键(SQL关键我认为)我怎么能转换器具它INT在其他方法使用从我的项目

我试图做它从会话恢复的ID

getInicioR :: Handler Html 
getInicioR = do 
     uid <- lookupSession "_ID" 
     user <- runDB $ get404 uid 

显示以下错误消息:

Couldn't match expected type ‘Key t0’ with actual type ‘Maybe Text’ 
In the first argument of ‘get404’, namely ‘uid’ 
In the second argument of ‘($)’, namely ‘get404 uid’ 

回答

2

使用keyToValues可获得PersistValue值的列表。

keyToValues :: Key record -> [PersistValue] 

如果你知道的,例如,该密钥是一个文本值,那么你的列表将包含单个PersistText值,你可以这样进行:

do uid <- lookupSession "_ID" 
    let pvals = keyToValues uid 
     [ PersistText txt ] = pvals 
    liftIO $ print pvals   -- to see what pvals is 
    -- now txt is a Text value 
    ...