Building dynamic queries with operators



I am building queries based on user input (search form) like this:
[:find ?e :in $ ?a1 ?a2 :where [ [?e :user/name ?a1] [(>?e :user/birthdate ?a2)]

Currently I build the query as a String.
This blog uses the map/list syntax:

Is it possible to add constraints to the where clause using this syntax that leverage operators like >, <, fulltext, ?missing, etc. (in Java)?

I’m also wondering (maybe different question) if indexes are used if the operator is ‘>’.
As a side effect of my query construction, equality is added as :where [ [(= ?e :user/name ?a)] ]. I’m not sure if this is bad for performance compared to [?e :user/name ?a].

Thanks for any tips regarding dynamic query generation.



The query syntax should be the same whether you’re building it with the Util functions or as a string.

Datomic does use index optimizations for comparison operators (<, >, <=, >=).
Equality using = will work fine, but the query engine will handle joins across multiple clauses differently using =. If possible, I would recommend using native datalog for cases where you want to join across a specific attribute.