'Query values for more than one entity in a single datomic query (Roam Alpha Api)
I'd like to in a single datomic/datalog query get output relating to multiple entities
E.g.
In my db (querying Roam graph via RoamAlphaApi) for one value ("YjpbFUsTx") I can do this:
[:find ?e ?stri :where [?e :block/uid "YjpbFUsTx"][?e :block/string ?stri]]
gives me
| ?e | ?stri |
|---|---|
| 420 | Hello |
But I want to pass on two values "YjpbFUsTx" and "TgpgOssBM"
to give me
| ?e | ?stri |
|---|---|
| 420 | Hello |
| 624 | Perfect |
How do I do that?
I've tried several variations but none give any output.
Useful reference: https://www.zsolt.blog/2021/01/Roam-Data-Structure-Query.html .
Solution 1:[1]
You can pass collections into a parametrized query. Have a look in the documentation: https://docs.datomic.com/on-prem/best-practices.html#collections-as-inputs
(d/q
'[:find ?e ?stri
:in $ [?uid ...]
:where
[?e :block/uid ?uid]
[?e :block/string ?stri]]
db ["YjpbFUsTx" "TgpgOssBM"])
; =>
#{[420 "Hello"][624 "Perfect"]}
On another note:
I suspect, your :block/uid is a unique identifier?
If you have :db/unique :db.unique/identity set for the attribute, you should use d/pull-many in this situation:
(d/pull-many db
[:db/id :block/string]
[[:block/uid "YjpbFUsTx"] [:block/uid "TgpgOssBM"]])
; =>
[{:db/id 420
:block/string "Hello"}
{:db/id 624
:block/string "Perfect"}]
Solution 2:[2]
The only way I found until now is manipulating the DOM, then set innerHTML. But I don't think this is a good way because we can't control DOM as this is generated by library, not by me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MrEbbinghaus |
| Solution 2 | vanminhquangtri |
