2016-06-08 63 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 
    ...