Fork me on GitHub
#datomic
<
2020-03-20
>
drewverlee17:03:01

Is there an easy way to construct the where clause for a query? Like conditionaly i want this where clause or this one.

favila17:03:59

cond-> and a steady hand

favila18:03:23

is it not an appropriate use for a or or rule?

drewverlee18:03:59

gotcha. I was trying to remember how programmatic queries worked. https://docs.datomic.com/on-prem/query.html#building-queries-programmatically

drewverlee18:03:18

The other options you mentioned might work to for my case.

favila18:03:08

but not always. ad-hoc filters is one case where it’s just easier and more predictable performance to add/remove clauses

favila18:03:29

but keep clause order deterministic, so you can still leverage caching

dustingetz13:03:56

@U0DJ4T5U1 you want backtick https://github.com/brandonbloom/backtick

(let [needle "foo"]
  (template
    [[(clojure.string/includes? ?name ~needle)]]))
=> [[(clojure.string/includes? ?name "foo")]]
Yes be sure that you aren’t blowing out number of static queries, parameterize them appropriately if possible, injecting a string constant in this way would be a really bad idea, but injecting a clause based on a predicate would be fine as it emits only two possible queries

drewverlee14:03:45

What i feel i need to express is the idea of conditionally picking the part of the where clauses. d/q [:find ?x :where [?a :fname "drew"] (if some-conditional [?a :lname "verlee"] [?a :age 15] I think i need to insert the entire clause(s) as opposed to just an entity, attribute or value.

favila14:03:21

is this because you have a multiparameter search interface, and some fields can be unused?

favila14:03:40

Just wondering what your use case is. What you wrote here is possible but not the best--parameterization is better; conditionally emitting clauses can sometimes be ok but still using parameterization