This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-24
Channels
If I want all entities of a certain type, what's the correct way to do this? I'm doing the following but it feels wrong.
(d/q '[:find [(pull ?e [*]) ...]
:in $ ?id-attr
:where
[?e ?id-attr _]]
(d/db conn)
id-attr)
Ah, a tiny bit buried: First, you have to pass the rule set as an input source and reference it in the :in section of your query using the '%' symbol.
Suggestion: An actual example of a query with rule right there in the "rules" section?
Super cool. Rules to do a "do some of these not-always present attributes contain this string" works really well.
Is there a way to parameterize a pull expression inside a query? I want to do something like:
(d/q '[:find [(pull ?e
?pull-exp) ...]
:in $ ?id-attr ?pull-exp
:where
[?e ?id-attr]]
(d/db conn)
:user/id
[:user/first-name {:user/task [:task/id]}])
But I get the following error:
:db.error/invalid-pull Invalid pull expression (pull ?e ?pull-exp)
I have to write several queries like and it would be nice to be DRY and avoid writing macros...
So I figured out I can work around with the back quote.
(let [pull-exp [:user/first-name :user/last-name :user/id
:user/email {:user/task [:task/id]}]]
(->> (d/q `[:find [(~'pull ~'?e
~pull-exp) ...]
:in ~'$
:where
[~'?e :user/id]]
(d/db conn))
(map normalize)))
Not sure if this is an anti-pattern though.Oh, hm. Maybe @currentoor is the alert? Oy. Slack.
Oh does ?
have special semantic meaning?
Yup that worked. Thanks!