I am new to Datomic and I am trying to understand how I would go about doing a query that is case insensitive.
For Example:
[:find (pull ?u [:user/email])
     :where [?u :user/email "[email protected]"]]
Returns:
{:user/email "[email protected]"}
I would like this query to return the same value for an email specified as "[email protected]" but Datomic is doing a case sensitive comparison on email as seen here.
[:find (pull ?u [:user/email])
     :where [?u :user/email "[email protected]"]]
Returns:
Nothing
Any suggestions on the best way to form the query so it does a case sensitive comparison?
Just convert query string and database item to lowercase.
   (defn case-insensitive-get-email
      [email]
      (d/q '[:find ?lowercaseEmail .
             :in $ ?email
             :where
             [?e :user/email ?originalEmail]
             [(.toLowerCase ^String ?originalEmail) ?lowercaseEmail]
             [(= ?lowercaseEmail ?email)]]
      db (.toLowerCase email)
           )
      )
Then
(case-insensitive-get-email "[email protected]") 
will return
"[email protected]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With