2
votes

I am very new to Datomic but I see value in Datomic's history keeping - considering what we need in our application.

My very basic question is, does Datomic help stop duplicating value to an attribute (let us say I keep adding name="my name" again and again becuase user presses save button without making any change to name)?

One another thing that is needed in our app is the ability to query the approved information rather than latest change. My question is, can I add attributes ("approved", "proposed" etc) to the transaction and query data based on these attributes?

Thanks!

2
I think the answer is yes for both questions, but please add some sample code in in-memory db style (a Clojure map, I suppose?) so it's clearer to see what you want to do - myguidingstar

2 Answers

1
votes

In Datomic, objects (or Clojure maps) are broken into datoms (aka tuples of key/value pairs associated with their owner).

  1. For question one, you can set your 'name' attribute to unique in your Datomic schema. Btw, it's recommended to use namespace-qualified keyword for attribute, something like :user/name.

  2. Just set the key for approved information to "many" in your schema

    {:comment/approved {:db/cardinality :db.cardinality/many}}

1
votes
  1. Repeated datoms will not be recorded again. Calls to add attributes/entities that already exist will be handled as upserts. If you define unique attributes, based on whether you select by "value" or "identity", repeated assertions may fail or upsert, see the docs here and here.

  2. You can annotate transactions. Instructions for doing so are in the docs here and you can find an example in the github repository for day-of-datomic, specifically this section:

(def db (:db-after @(d/transact conn [{:db/id (d/tempid :db.part/user) :story/title "ElastiCache in 5 minutes" :story/url "http://blog.datomic.com/2012/09/elasticache-in-5-minutes.html"} {:db/id (d/tempid :db.part/tx) :source/user editor}])))