Skip to content
Decorators for extending the core Crux API
Clojure
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/crux/decorators
test
.gitignore
README.adoc
project.clj

README.adoc

Decorators

Overview

Decorators are features that can be built on top of Crux that can be used optionally and can be created easily without needing understand how the core of Crux works. Use of decorators is currently an advanced topic and requires a basic understanding of Clojure to configure.

Aggregation

The aggregation.alpha namespace demonstrates a good example of building a highly general aggregation extension to the basic Crux query. The standard api/q function can now be ignored as the aggr/q function is used instead (it wraps api/q with transducer magic).

This project also includes an aggregation decorator. For usage examples, see aggregation_test.clj and graph-traversal.clj.

  ;; tag::aggr1[]
  (t/deftest test-count-aggregation
    (f/transact-entity-maps!
     *kv*
     [{:crux.db/id :a1 :user/name "patrik" :user/post 1 :post/cost 30}
      {:crux.db/id :a2 :user/name "patrik" :user/post 2 :post/cost 35}
      {:crux.db/id :a3 :user/name "patrik" :user/post 3 :post/cost 5}
      {:crux.db/id :a4 :user/name "niclas" :user/post 1 :post/cost 8}])

    (t/testing "with vector syntax"
      (t/is (= [{:user-name "niclas" :post-count 1 :cost-sum 8}
                {:user-name "patrik" :post-count 3 :cost-sum 70}]
               (aggr/q
                (api/db *api*)
                '{:aggr {:partition-by [?user-name]
                         :select
                         {?cost-sum [0 (+ acc ?post-cost)]
                          ?post-count [0 (inc acc) ?e]}}
                  :where [[?e :user/name ?user-name]
                          [?e :post/cost ?post-cost]]})))))

See the aggregation_test.clj for more examples of usage.

You can’t perform that action at this time.