datascript

cjohansen 2025-06-11T10:59:18.134949Z

We just discoverered that Datascript compares entities differently from Datomic. This surprised us quite a bit, is there a rationale for this difference? Example in ๐Ÿงต

cjohansen 2025-06-11T11:00:08.501889Z

(let [conn (d/create-conn {:person/id {:db/cardinality :db.cardinality/one
                                       :db/unique :db.unique/identity}})]
  (d/transact! conn [{:person/id "bob"
                      :person/name "Bob"
                      ;;:person/friends ["alice" "wendy"]
                      }])
  (let [bob (d/entity @conn [:person/id "bob"])]
    (d/transact! conn [{:db/id "alice"
                        :person/id "alice"
                        :person/boss "wendy"
                        :person/name "Alice"}])
    (let [bob2 (d/entity @conn [:person/id "bob"])]
      [(:db/id bob)
       (:db/id bob2)
       (= bob bob2)
       ])
    )
  )
This returns [1 1 false] in Datascript and [17592186045418 17592186045418 true] in Datomic

cjohansen 2025-06-11T11:00:45.564849Z

My understanding: Datomic considers :db/id to uniquely define equality for entities, while Datascript seems to use :db/id plus database value as the basis for comparison.

Niki 2025-06-11T12:46:03.001529Z

It probably uses database's T value, not the entire database. I donโ€™t remember if there was a specific reason, might be just common sense

Niki 2025-06-11T12:46:25.826569Z

Unfortunately that means Iโ€™m not sure if I can safely change that behaviour

cjohansen 2025-06-11T13:04:13.022339Z

Yeah, I guessed it would be the T value. Understandable, but this is a bit of a footgun when coming from Datomic ๐Ÿ˜…

Niki 2025-06-11T15:18:52.913669Z

Sorry

Niki 2025-06-11T15:19:08.025629Z

You can always compare entity ids yourself

cjohansen 2025-06-11T16:13:41.565009Z

๐Ÿ‘