如何将XyzId转换为持久性中的整数?

时间:2014-07-22 12:00:47

标签: haskell yesod persistent

在Persistent中,如何将XyzId(PersonId,whateverid)转换为其表示的整数?

2 个答案:

答案 0 :(得分:5)

您可以使用unKey从该身份获取PersistValue,并通过模式匹配从中获取整数:

intKey ::  PersistEntity val => Key val -> Int64
intKey key = case unKey key of
    PersistInt64 int64 -> int64
    _ -> error "BUG: Unexpected ident"

答案 1 :(得分:0)

Key不保证是整数,但保证为PathPiece,这在文件名中使用会更有用。

相关问题