Liking cljdoc? Tell your friends :D

About

ClaraEAV is a thin layer over Clara-Rules API that simplifies working with EAV triplets, similar to Triplestores.

The main benefit of EAV triplets over Clara's default n-tuples (arbitrary records) is that updates (equivalent to a retraction and an insertion) are local to the attribute (EAV triplet). Updating an n-tuple requires retraction and re- insertion of the whole tuple. The downside is extra joins are needed to build back an entity from it's constituent EAVs.

Installation

Clara releases are on Clojars. Add the following to your project dependencies:

[clyfe/clara-eav "0.1.0"]

Usage

You should be familiar with Clara Rules before using ClaraEAV.

The clara-eav.rules namespace mirrors clara.rules for the most part, and adds two accumulators to build back entity maps from stored EAV triplets.

For more information see the Guide and API Docs. Tests can be useful, see: test_rules.cljc for rules and queries definition and rules_test.cljc for sample usage.

(ns sample
  (:require [clara.rules :as r]
            [clara-eav.rules :as er]))

(er/defquery todo-q [:?e] 
  [?todo <- er/entity :from [[?e]]])

(er/defsession session 
  'sample)

(def tx
  #:todo{:db/id :new
         :text "..."
         :done false})

(-> session
    (er/upsert tx)
    (r/fire-rules)
    (r/query todo-q :?e :new))

; ({:?e :new, :?todo #:todo{:db/id :new, :text "...", :done false}})

Credits

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close