Fork me on GitHub
#datascript
<
2020-09-22
>
Misha Gusarov07:09:45

Hello folks. How do I group results in Datascript query? Is there a faster way than "query the whole result set, then group-by "?

oly13:09:27

@misha470 guess it depends what you mean but datalog does have aggregates for grouping http://www.learndatalogtoday.org/chapter/7

Misha Gusarov13:09:20

@oliver.marks I mean something like the following: "query all entities, grouped by :entity/bar and :entity/baz " -> {[:a :b] [{:entity/name "xxx" :entity/bar :a :entity/baz :b} {:entity/name "yyy" :entity/bar :a :entity/baz :b}] [:a :d] [{:entity/name "zzz" :entity/bar :a :entity/baz :d}] [:c :e] [{:entity/name "qqq" :entity/bar :c :entity/baz :e} {:entity/name "www" :entity/bar :c :entity/baz :e}]}

Misha Gusarov13:09:39

"all entities" will vary, of course.

Misha Gusarov13:09:54

Though it looks like there is no point doing it in Datascript: clojure.core/group-by is just fine.