datahike

https://datahike.io/, Join the conversation at https://discord.com/invite/kEBzMvb, history for this channel is available at https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/datahike
bartuka 2020-02-26T04:03:57.003100Z

hi! I met the project because of my simple impl of a similar idea. Congrats by the complete solution!! I was studying a particular situation to implement in my scenario as well. The question is more like, what is the correct answer for the sequence of transactions below? What happened with the transaction I did with the conn2 value?

(def uri "datahike:file:///tmp/file_example")

(def schema-tx [{:db/ident :name
                 :db/valueType :db.type/string
                 :db/unique :db.unique/identity
                 :db/index true
                 :db/cardinality :db.cardinality/one}

                {:db/ident :age
                 :db/valueType :db.type/long
                 :db/cardinality :db.cardinality/one}])

(d/delete-database uri)
(d/create-database uri :initial-tx schema-tx)
(def query '[:find ?n ?a :where [?e :name ?n] [?e :age ?a]])

;;; connection one
(def conn (d/connect uri))
(d/transact conn [{:name "Alice" :age 25} {:name "Bob" :age 30}])
(d/q query @conn)
;; => #{["Alice" 25] ["Bob" 30]}


;;; new connection with the new database state
(def conn2 (d/connect uri))
(d/transact conn2 [{:name "Alice Mother" :age 60} {:name "Bob Father" :age 52}])
(d/q query @conn2)
;; => #{["Alice" 25] ["Alice Mother" 60] ["Bob Father" 52] ["Bob" 30]}


;;; transact again with connection one
(d/transact conn [{:name "Alice Grandmother" :age 90}])
(d/q query @conn)
;; => #{["Alice" 25] ["Alice Grandmother" 90] ["Bob" 30]}


;;; new connection 3... what should be the database state?
(def conn3 (d/connect uri))

(d/q query @conn3)
;; => #{["Alice" 25] ["Alice Grandmother" 90] ["Bob" 30]}
(d/q query (d/history @conn3))          ;even in the history db
;; => #{["Alice" 25] ["Alice Grandmother" 90] ["Bob" 30]}