Skip to content

Instantly share code, notes, and snippets.

@ulsa
Created June 27, 2012 14:45
Show Gist options
  • Save ulsa/3004531 to your computer and use it in GitHub Desktop.
Save ulsa/3004531 to your computer and use it in GitHub Desktop.
Finding Out Who Changed What with Datomic
user=> (distinct (map :e (d/datoms (d/since (db conn) #inst "2012-06-25T10:33:16.436-00:00") :eavt)))
(13194139534683 17592186045460)
user=> (->> (-> (db conn)
(d/since #inst "2012-06-25T10:33:16.436-00:00")
(d/datoms :eavt))
(map :e)
distinct)
(13194139534683 17592186045460)
user=> (count (q '[:find ?c ?n
:where [?c :community/name ?n]
[ (.compareTo ?n "B") ?res ]
[ (< ?res 0) ] ] (db conn)))
9
user=> (use '[datomic.api :only (q db) :as d])
user=> (use 'clojure.pprint)
user=> (pprint (seq (q '[:find ?c ?n
:where [?c :community/name ?n]
[ (.compareTo ?n "B") ?res ]
[ (< ?res 0) ] ] (db conn))))
([17592186045463 "Aurora Seattle"]
[17592186045454 "All About South Park"]
[17592186045448 "Alki News/Alki Community Council"]
[17592186045446 "Alki News"]
[17592186045460 "At Large in Ballard"]
[17592186045457 "ArtsWest"]
[17592186045451 "All About Belltown"]
[17592186045440 "15th Ave Community"]
[17592186045443 "Admiral Neighborhood Association"])
nil
user=> (pprint (seq (q '[:find ?c ?n ?t
:where [?tx :db/txInstant ?t]
[?c :community/name ?n ?tx]
[ (.compareTo ?n "B") ?res ]
[ (< ?res 0) ] ] (db conn))))
([17592186045451 "All About Belltown"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045463 "Aurora Seattle"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045460 "At Large in Ballard"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045454 "All About South Park"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045457 "ArtsWest"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045440 "15th Ave Community"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045446 "Alki News"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045443 "Admiral Neighborhood Association"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045448 "Alki News/Alki Community Council"
#inst "2012-06-25T10:33:16.436-00:00"])
nil
user=> (pprint (seq (q '[:find ?c ?n ?txInstant
:where [?tx :db/txInstant ?txInstant]
[?c :community/name ?n ?tx]
[ (.compareTo ?n "B") ?res ]
[ (< ?res 0) ] ] (db conn))))
([17592186045451 "All About Belltown"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045463 "Aurora Seattle"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045460 "At Large in Ballard renamed"
#inst "2012-06-25T10:55:47.363-00:00"]
[17592186045454 "All About South Park"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045457 "ArtsWest"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045440 "15th Ave Community"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045446 "Alki News"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045443 "Admiral Neighborhood Association"
#inst "2012-06-25T10:33:16.436-00:00"]
[17592186045448 "Alki News/Alki Community Council"
#inst "2012-06-25T10:33:16.436-00:00"])
nil
user=> (class #inst "2012-06-25T10:33:16.436-00:00")
java.util.Date
user=> (.getTime #inst "2012-06-25T10:33:16.436-00:00")
1340620396436
user=> @(d/transact conn [{:db/id 17592186045460 :community/name "At Large in Ballard renamed"}])
user=> (def uri "datomic:mem://seattle")
user=> (d/create-database uri)
user=> (def conn (d/connect uri))
user=> @(d/transact conn (read-string (slurp "samples/seattle/seattle-schema.dtm")))
user=> @(d/transact conn (read-string (slurp "samples/seattle/seattle-data0.dtm")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment