Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datomic: Case insensitive query

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?

like image 641
Jeff Slavin Avatar asked Oct 25 '25 20:10

Jeff Slavin


1 Answers

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]"
like image 124
woryzower Avatar answered Oct 28 '25 21:10

woryzower