1

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?

duplode
  • 33,731
  • 7
  • 79
  • 150
Eric
  • 663
  • 4
  • 14

1 Answers1

1

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 a PersistEntity Key into a BackendKey This can be used by each backend to convert between a Key and a plain Haskell type.

Community
  • 1
  • 1
duplode
  • 33,731
  • 7
  • 79
  • 150