datahike

silian 2024-05-25T22:41:32.023509Z

Is the following expected behavior?

(defn naive-find-username-eid [username-string]
  (d/q `[:find ?e
         :where
         [?e :user/username ~username-string]]
       @conn))

(naive-find-username-eid nil) ;; => #{[774]}
When provided nil , naive-find-username-eid will return the eid for (the first and only) user in my system.

silian 2024-05-27T07:17:37.570519Z

Thanks timo

timo 2024-05-27T06:58:49.276779Z

Take a look at https://docs.datomic.com/query/query-data-reference.html#inputs though not related to your specific problem.

1
silian 2024-05-25T22:47:27.953799Z

I think the above behavior makes sense. I am probably writing non-idiomatic code. To adjust, I re-wrote my fn as follows:

(defn find-username-eid [username-string]
  (if-not (nil? username-string)
   (ffirst
    (d/q `[:find ?e
           :where
           [?e :user/username ~username-string]]
         @conn))))
But I thought it was interesting — my first time revising my expectations of the concept of nil :)