MongoDB 键的 PersistValues Yesod/Persistent 2
PersistValues for MongoDB Keys in Yesod/Persistent 2
我有一些代码在 persistent < 2
中执行以下操作:
(either (\_ -> 0) id).fromPersistValue.unKey.entityKey $ myEntity
如何使用 persistent > 2
实现相同的功能,因为 keys
现在由各个后端定义,因此没有 unKey
功能?在较新版本的 Persistent 中,MongoDB 键还需要实现这些 "Int representations" 吗?
似乎有一个 keyToOid
function that does approximately what you want in Database.Persist.MongoDB
. From the Persistent docs,我收集到的变化是从后端抽象密钥的一部分:
class (PersistEntity record, PersistEntityBackend record ~ backend, PersistStore backend) => ToBackendKey backend record where
ToBackendKey
converts a PersistEntity Key
into a BackendKey
This can be used by each backend to convert between a Key
and a plain Haskell type.
我有一些代码在 persistent < 2
中执行以下操作:
(either (\_ -> 0) id).fromPersistValue.unKey.entityKey $ myEntity
如何使用 persistent > 2
实现相同的功能,因为 keys
现在由各个后端定义,因此没有 unKey
功能?在较新版本的 Persistent 中,MongoDB 键还需要实现这些 "Int representations" 吗?
似乎有一个 keyToOid
function that does approximately what you want in Database.Persist.MongoDB
. From the Persistent docs,我收集到的变化是从后端抽象密钥的一部分:
class (PersistEntity record, PersistEntityBackend record ~ backend, PersistStore backend) => ToBackendKey backend record where
ToBackendKey
converts aPersistEntity Key
into aBackendKey
This can be used by each backend to convert between aKey
and a plain Haskell type.