-
I have the following data in a in-memory node: (ns user
(:require
[xtdb.api :as xt]
[xtdb.node :as xt.node]))
(def n (xt.node/start-node {}))
(xt/submit-tx n [[:put :store {:xt/id 0
:name "Some Store"
:inventory
[{:display "Cool shirt"
:price 10.99
:tags [:cool :shirt :trending]}]}]]) I am then attempting to query/filter results based off a certain tag being present in the list/collection. With my current mental model, I am under the impression that the (xt/q n '{:find [display price store-id]
:where [($ :store [{:xt/id store-id, :inventory [inventory ...]}])
[(. inventory :display) display]
[(. inventory :price) price]
[(. inventory :tags) [tags ...]]
[(= tags :trending)]]}) I'm sure my mental model of datalog isn't correct, which is leading me to bash my head against a wall. Furthermore, this would all be alleviated with normalizing the tags into their own table, like so. (xt/submit-tx n [[:put :store {:xt/id 0
:name "Some Store"
:inventory
[{:display "Some cool shirt"
:price 10.99
:tag-ids #{0 1 2}}]}]
[:put :tags {:xt/id 0, :tag :trending}]
[:put :tags {:xt/id 1, :tag :cool}]
[:put :tags {:xt/id 2, :tag :shirt}]]) But even with the above, I am not sure how to query based on the tag-ids set. Even though the data models are non optimal (i.e. not totally normalized), I am mainly attempting to exercise and wrap my head around what is possible with xtdb. If the above example is possible to perform, any help with correcting my mental model would be greatly appreciated 🙂 Finally, I haven't had a long time to write this question out and proof all the tx/q operations, but I think they catch the gist of my meaning. If not, and there isn't clarity, I am happy to delve further and have a dialogue! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Found this issue: #2707 Seems to apply in this case, however, attempting to do the following results in a malformed query error. The following example assumes the first data model mentioned in the OP: (xt/q n '{:find [store-id item]
:where [($ :stores [{:xt/id store-id} inventory])
($ [inventory {:as item}])]}) |
Beta Was this translation helpful? Give feedback.
-
Saw the post which direct to post on discuss.xtdb.com: https://discuss.xtdb.com/t/2-x-how-filter-query-results-based-on-nested-vector-values/257 This thread should be consider moot. |
Beta Was this translation helpful? Give feedback.
Saw the post which direct to post on discuss.xtdb.com: https://discuss.xtdb.com/t/2-x-how-filter-query-results-based-on-nested-vector-values/257
This thread should be consider moot.