threatgrid / asami

A graph store for Clojure and ClojureScript
Eclipse Public License 1.0
634 stars 29 forks source link

Appending references to arrays #225

Open zeitstein opened 2 years ago

zeitstein commented 2 years ago

Directly appending the referenced :db/id works, but not the usual {:db/id ...} syntax; same for :db/ident and :id. Example initial data:

[{:db/ident 0 :child [{:db/ident 1}]}
 {:db/ident 1 :data "1"}]

Transacting the following doesn't work:

[{:db/ident 2 :data "2"}
 {:db/ident 0 :child+ {:db/ident 2}}]

;; inserted into the array as:
;; #datom [:tg/node-25760 :tg/first #:db{:ident 2} 2 true]

This works:

[{:db/ident 2 :data "2" :db/id :tg/node-2}
 {:db/ident 0 :child+ :tg/node-2}]

But not temporary ids:

[{:db/id -1 :db/ident 3 :data "3"}
 {:db/ident 0 :child+ -1}]

;; inserted into the array as
;; #datom [:tg/node-25728 :tg/first -1 2 true]
zeitstein commented 2 years ago

Clearer examples. None of the below work:

  ;; initial
  (d/transact conn [{:id 1}
                    {:id 0 :array [{:id 1}]}])

  (d/transact conn [{:id "new"}
                    {:id 0 :array+ {:id "new"}}])

  (d/transact conn [{:id "new"}
                    {:id 0 :array+ [:id "new"]}])

  (d/transact conn [{:id "new2"}
                    {:id 0 :array+ "new2"}])

  (d/transact conn [{:id "new3" :db/id -1}
                    {:id 0 :array+ -1}])

The only thing that works is:

  (d/transact conn [{:db/id :tg/node-1}
                    {:db/id :tg/node-0 :array [{:db/id :tg/node-1}]}])

  (d/transact conn [{:db/id :tg/node-new}
                    {:db/id :tg/node-0 :array+ :tg/node-new}])