Fork me on GitHub
#datahike
<
2022-06-25
>
Benjamin14:06:00

combining tuple attrs and unique/identity does not work like I expect. When I assert the same combination of attributes a second time there is an error

Benjamin14:06:14

(require '[datahike.api :as d])
(def schema
  [{:db/ident :foo/idx
    :db/valueType :db.type/long
    :db/cardinality :db.cardinality/one}
   {:db/ident :foo/parent
    :db/valueType :db.type/ref
    :db/cardinality :db.cardinality/one}
   {:db/ident :bar/hash
    :db/unique :db.unique/identity
    :db/valueType :db.type/string
    :db/cardinality :db.cardinality/one}
   {:db/ident :foo/id
    :db/valueType :db.type/tuple
    :db/cardinality :db.cardinality/one
    :db/unique :db.unique/identity
    :db/tupleAttrs [:foo/parent :foo/idx]
    :db/doc "The id of a foo, it is made up of parent and idx"}])


(def cfg {:store {:backend :mem :initial-tx schema :id "foos"}})
(do (d/delete-database cfg) nil)
(d/create-database cfg)
(def conn (d/connect cfg))

(d/transact conn schema)

(d/transact conn {:tx-data [{:foo/idx 1
                             :foo/parent
                             {:bar/hash "1"}}]})


(d/transact conn {:tx-data [{:foo/idx 1
                             :foo/parent
                             {:bar/hash "1"}}]})

*e


 :cause "Cannot add #datahike/Datom [7 :foo/id [6 1] 536870915 true] because of unique constraint: #datahike/Datom [5 :foo/id [6 1] 536870914 true]"

metasoarous17:06:43

This issue might be specifically be related to :foo/parent being a ref. I'd suggest trying with a non ref attribute to verify. Not sure I can help much more than that though.