I have some code that was doing the following in persistent < 2
:
(either (\_ -> 0) id).fromPersistValue.unKey.entityKey $ myEntity
How can I achieve the same functionality using persistent > 2
as keys
are now defined by individual Backends and as such there is no unKey
function? Is there still away to achieve these "Int representations" for MongoDB keys in newer versions of Persistent?
It seems there is a keyToOid
function that does approximately what you want in Database.Persist.MongoDB
. From the Persistent docs, I gather the change was part of a move towards abstracting keys from backends:
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.