datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Misha Gusarov 2020-09-22T07:08:45.002800Z

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

oly 2020-09-22T13:24:27.004Z

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

Misha Gusarov 2020-09-22T13:39:20.007500Z

@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 Gusarov 2020-09-22T13:39:39.007800Z

"all entities" will vary, of course.

Misha Gusarov 2020-09-22T13:40:54.008800Z

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