Skip to content

Instantly share code, notes, and snippets.

@cap10morgan
Created August 20, 2013 17:59
Show Gist options
  • Save cap10morgan/6284911 to your computer and use it in GitHub Desktop.
Save cap10morgan/6284911 to your computer and use it in GitHub Desktop.
Datomic entity creation, querying, and retraction
elections-api.peer=> (init-db)
#<promise$settable_future$reify__5429@127cc7ca: {:db-before datomic.db.Db@1ea21c76, :db-after datomic.db.Db@61f108a4, :tx-data [#Datum{:e 13194139534313 :a 50 :v #inst "2013-08-20T17:13:49.111-00:00" :tx 13194139534313 :added true} #Datum{:e 17592186045418 :a 10 :v :election-constructor :tx 13194139534313 :added true} #Datum{:e 17592186045418 :a 52 :v #db/fn{:code "(if (not (nil? district)) (let [txn [(merge district [:db/id #db/id[:db.part/user -2]]) (merge election {:db/id #db/id[:db.part/user -1], :turbovote.election/district #db/id[:db.part/user -2]})]] txn) (let [txn [(merge election {:db/id #db/id[:db.part/user -1]})]] txn))", :params [db election district], :requires [], :imports [], :lang :clojure} :tx 13194139534313 :added true}], :tempids {-9223350046623220306 17592186045418}}>
elections-api.peer=> (def conn (d/connect "datomic:mem://elections-api"))
#'elections-api.peer/conn
elections-api.peer=> (d/transact conn [[:election-constructor {:turbovote.election/name "Foo Election" :turbovote.election/date (to-date "2013-08-20")} nil]])
#<promise$settable_future$reify__5429@5c397c34: {:db-before datomic.db.Db@61f108a4, :db-after datomic.db.Db@d1e093a7, :tx-data [#Datum{:e 13194139534315 :a 50 :v #inst "2013-08-20T17:22:49.982-00:00" :tx 13194139534315 :added true} #Datum{:e 17592186045420 :a 62 :v "Foo Election" :tx 13194139534315 :added true} #Datum{:e 17592186045420 :a 63 :v #inst "2013-08-20T00:00:00.000-00:00" :tx 13194139534315 :added true}], :tempids {-9223350046622220289 17592186045420}}>
elections-api.peer=> (q '[:find ?e :where [?e :turbovote.election/name ?n] [?e :turbovote.election/date ?d]] (d/db conn))
#{[17592186045420]}
elections-api.peer=> (d/transact conn '[[:db.fn/retractEntity 17592186045420]])
#<promise$settable_future$reify__5429@38dea1: {:db-before datomic.db.Db@d1e093a7, :db-after datomic.db.Db@2f45538c, :tx-data [#Datum{:e 13194139534317 :a 50 :v #inst "2013-08-20T17:34:58.819-00:00" :tx 13194139534317 :added true} #Datum{:e 17592186045420 :a 62 :v "Foo Election" :tx 13194139534317 :added false} #Datum{:e 17592186045420 :a 63 :v #inst "2013-08-20T00:00:00.000-00:00" :tx 13194139534317 :added false}], :tempids {}}>
elections-api.peer=> (q '[:find ?e :where [?e :turbovote.election/name ?n] [?e :turbovote.election/date ?d]] (d/db conn))
#{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment