[英]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我想在单个 datomic/datalog 查询中获取与多个实体相关的输出
Eg例如
In my db (querying Roam graph via RoamAlphaApi) for one value ( "YjpbFUsTx"
) I can do this:在我的数据库中(通过 RoamAlphaApi 查询漫游图)中的一个值(
"YjpbFUsTx"
)我可以这样做:
[: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"
但我想传递两个值
"YjpbFUsTx"
和"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 .有用的参考: https ://www.zsolt.blog/2021/01/Roam-Data-Structure-Query.html。
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
查看文档: 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?另一方面:我怀疑,您的
:block/uid
是唯一标识符? If you have :db/unique :db.unique/identity
set for the attribute, you should use d/pull-many
in this situation:如果你为属性设置了
:db/unique :db.unique/identity
,你应该在这种情况下使用d/pull-many
:
(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"}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.