Skip to content

Instantly share code, notes, and snippets.

@ulsa
Created June 27, 2012 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ulsa/3004813 to your computer and use it in GitHub Desktop.
Save ulsa/3004813 to your computer and use it in GitHub Desktop.
Find Out Who Changed What with Datomic, 2
user=> @(d/transact conn
[{:db/id #db/id[:db.part/db]
:db/ident :audit/user
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/index true
:db.install/_attribute :db.part/db}])
user=> @(d/transact conn
[{:db/id #db/id[:db.part/db]
:db/ident :audit/user
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/index true
:db.install/_attribute :db.part/db}])
user=> @(d/transact conn
[{:db/id 17592186045460 :community/name "At Large in Ballard"}
[:db/add (d/tempid :db.part/tx) :audit/user "ulsa" ]])
user=> (def changed (->> (-> (db conn)
(d/since #inst "2012-06-25T10:33:16.436-00:00")
(d/datoms :eavt))
(map :e)
distinct))
user=> (def changed (->> (-> (db conn)
(d/since #inst "2012-06-25T10:33:16.436-00:00")
(d/datoms :eavt))
(map :e)
distinct))
user=> changed
(0 72 13194139534683 13194139534684 13194139534685 17592186045460)
user=> (def changed (->> (-> (db conn)
(d/since #inst "2012-06-25T11:13:23.642-00:00")
(d/datoms :eavt))
(map :e)
distinct))
user=> changed
(13194139534685 17592186045460)
user=> (use '[clojure.walk :only (macroexpand-all)])
user=> (macroexpand-all '(-> x (h 3) (g 2) (f 1)))
(f (g (h x 3) 2) 1)
user=> (macroexpand-all '(->> x (h 3) (g 2) (f 1)))
(f 1 (g 2 (h 3 x)))
user=> (macroexpand-all
'(->> (-> (db conn)
(d/since #inst "2012-06-25T10:33:16.436-00:00")
(d/datoms :eavt))
(map :e)
distinct))
(distinct (map :e (d/datoms (d/since (db conn) #inst "2012-06-25T10:33:16.436-00:00") :eavt)))
user=> (pprint (map #(seq (d/entity (db conn) %)) changed))
(([:db/txInstant #inst "2012-06-25T10:55:47.363-00:00"])
([:community/type :community.type/blog]
[:community/orgtype :community.orgtype/commercial]
[:community/category #{"news" "human interest"}]
[:community/neighborhood {:db/id 17592186045459}]
[:community/url "http://blog.seattlepi.com/ballard/"]
[:community/name "At Large in Ballard renamed"]))
nil
user=> (pprint (map #(seq (d/entity (db conn) %)) changed))
(([:audit/user "ulsa"]
[:db/txInstant #inst "2012-06-25T11:13:23.643-00:00"])
([:community/type :community.type/blog]
[:community/orgtype :community.orgtype/commercial]
[:community/category #{"news" "human interest"}]
[:community/neighborhood {:db/id 17592186045459}]
[:community/url "http://blog.seattlepi.com/ballard/"]
[:community/name "At Large in Ballard"]))
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment