Reputation: 116
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?
Upvotes: 4
Views: 905
Reputation: 976
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]"
Upvotes: 6
Reputation: 116
To perform a case insensitive query I formed the query using the Clojure re-find
function to perform a case insensitive regular expression match against the passed email as follows:
[:find (pull ?u [:user/email])
:where
[?u :user/email ?email]
[(re-find #"(?i)[email protected]" ?email)]
] db)
This now returns:
{:user/email "[email protected]"}
Upvotes: 5