Fork me on GitHub
#xtdb
<
2022-10-14
>
Jesse07:10:53

Hi all, I have question about Pull syntax for a query; are we able to access values from an inner map in a document? As I don't think we can use the braces syntax because they specify a join.

Jesse07:10:31

For example, what doesn't work:

;; doc: {:xt/id :ivan :user/name "Ivan" :user/details {:user/image "https://.." :user/bio "....."}} 

(xt/q
 (xt/db node)
 '{:find [(pull ?user [:user/name {:user/details [:user/image]}])]
   :where [[?user :user/id ?uid]]})
I would like to get only the :user/name and :user/image values returned

refset08:10:25

Hey @U03MWJ46V0Q - XT's pull will only work with the top-level document values (and joins across those). If you want to use a pull-like API to retrieve nested document values you might be able to combine XT with https://github.com/lilactown/pyramid (either within the XT query or outside, after the query returns)

1
Jesse09:10:13

Ok clear! I can indeed transform the data returned by the query then. I am using nested maps to avoid indexing of fields that don't need it. But I will miss not having XT pull for extracting them. Wrapping something like pyramid can work also :) Thanks!