yesod SqlBackendKey to Text

时间:2016-03-31 00:45:39

标签: yesod

是否可以将SqlBackendKey转换/解析为Real Text?

例如Model

UserInfo
    fullName Text
    ageBracket Text Maybe
    gender Text
    createdOn UTCTime default=now()
    updatedOn UTCTime Maybe
    deriving Show

User
    userInfoId UserInfoId
    username Text
    password Text
    UniqueUsername username
    deriving Show

我的代码:

-- let say the output of this
-- userInfoId  = 1 -- this is a
-- username = admin
-- paswword = admin
userData <- runDB $ selectFirst [UserUsername ==. uname , UsersPassword ==. pword] [LimitTo 1]


case userData of
            Nothing -> ....
            Just (Entity _ u) -> do
                let userInfoId = T.pack (show (userUserInfoId u))
                $(logInfo) userInfoId 
                .....

$(logInfo)userInfoId

的输出
[INFO] UserInfoKey {unUserInfoKey = SqlBackendKey {unSqlBackendKey = 1}}

我只需要数字“1”(一)。

1 个答案:

答案 0 :(得分:0)

You can use fromSqlKey.

fromSqlKey (userUserInfoId u)