Search code examples
clojurescriptomom-next

How do I query with a join getting all the data in Om Next?


In Om Next, when having data such as:

{:table      {:name "Disk Performance Table"
              :data [:statistics :performance]}
 :chart      {:name "Combined Graph"
              :data [:statistics :performance]}
 :statistics {:performance {:cpu-usage        [45 15 32 11 66 44]
                            :disk-activity    [11 34 66 12 99 100]
                            :network-activity [55 87 20 1 22 82]}}}

you can query it with:

[{:chart [{:data [:cpu-usage]}]}]

to get the chart, join the data and dig down cpu-usage from the performance record:

{:chart {:data {:cpu-usage [45 15 32 11 66 44]}}}

How do I get the whole performance record instead?

Another potential query is this:

[{:chart [:data]}]

but it doesn't resolve the join:

{:chart {:data [:statistics :performance]}}

There are no components as this is only about the data and the query. This is from the exercise number 2 and queries here: https://awkay.github.io/om-tutorial/#!/om_tutorial.D_Queries which uses om/db->tree to run the queries.


Solution

  • This is how you do it:

    [{:chart [{:data [*]}]}]
    

    which gives you:

    {:chart {:data {:cpu-usage        [45 15 32 11 66 44]
                    :disk-activity    [11 34 66 12 99 100]
                    :network-activity [55 87 20 1 22 82]}}}