1
votes

I have a datomic database that contains the following enum

{:db/id #db/id[:db.part/db]
  :db/ident :demographics/gender
  :db/valueType :db.type/ref
  :db/cardinality :db.cardinality/one
  :db/doc "A person's gender enum reference"
  :db.install/_attribute :db.part/db}

;; :demographics/gender enum values
{:db/id #db/id[:db.part/user]
  :db/ident :demographics.gender/male}

{:db/id #db/id[:db.part/user]
  :db/ident :demographics.gender/female}

{:db/id #db/id[:db.part/user]
  :db/ident :demographics.gender/other}

Now say that I do:

(d/entity db ...)

And obtain a lazy map containing an entity and its attributes, the enum above included. I now want to obtain a string representation of the enum value that I get as a response from my query. My idea was to do this:

(def ^:private gender-map {:demographics.gender/male "Male" 
                           :demographics.gender/female "Female" 
                           :demographics.gender/other "Other"})

and then this

(gender-map (lazy-map :demographics/gender))

However, that did not work. What would be the correct way to do this?

Thanks

1
Turns out that I had the order wrong when trying to obtain the value in the map. I just needed to switch the places of the key and the (d/entity db ...) result and I got the enum value as a string (e.g. "male"). The gender-map was therefore unnecessary. - Litterate
You should consider to either delete your question or to accept my answer. Btw.: It isn't clear from your comment where the keyword to string conversion happens or what order was wrong. - Leon Grapenthin

1 Answers

0
votes

lazy-map is not defined in your example. If it is the result returned from (d/entity ...) check whether it has a valid :demographics/gender entry.