I’m seeing some behavior in datomic cloud, that is contrary to what I’ve been led to believe as “the database as a value”. When I acquire a “current” DB value from a connection, using d/db
fn, and try to compare that to another DB value, using =
, which is of the same t basis, I get false
. This appears to be the case when doing both a remote connection to a system, and from within an ions application.
;; Remote connection, using :server-type :ion
(let [c (conn "core-prod" "XXXX.core.prod")
db1 (d/db c)
db2 (d/db c)]
{:db1 db1
:db2 db2
:eq? (= db1 db2)
:type (type db1)})
;; => {:db1
;; {:t 3150, :next-t 3151, :db-name "XXXX.core.prod", :database-id "de0a365c-eb28-4cf4-a490-bd0bcfff8104", :type :datomic.client/db},
;; :db2
;; {:t 3150, :next-t 3151, :db-name "XXXX.core.prod", :database-id "de0a365c-eb28-4cf4-a490-bd0bcfff8104", :type :datomic.client/db},
;; :eq? false, ;; ** This is not expected **
;; :type datomic.client.impl.shared.Db}
When using dev-local I do see the expected behavior however:
;; dev-local connection, using dl/divert-system
(let [c (conn)
db1 (d/db c)
db2 (d/db c)]
{:db1 db1
:db2 db2
:eq? (= db1 db2)
:type (type db1)})
;; => {:db1
;; #datomic.core.db.Db{:id "import-202123-1720", :basisT 3151, :indexBasisT -1, :index-root-id nil, :asOfT nil, :sinceT nil, :raw nil},
;; :db2
;; #datomic.core.db.Db{:id "import-202123-1720", :basisT 3151, :indexBasisT -1, :index-root-id nil, :asOfT nil, :sinceT nil, :raw nil},
;; :eq? true, ;; This was expected
;; :type datomic.core.db.Db}
Having a tangible database value, that can be compared to other database values (with =
fn) was a very big reason to choose datomic; see Rich’s Talk. I definitely understand that the two values may not be identical?
, but surely, since they are the same T basis and both their as-of and since basis’ are the same, then the two DBs should be equal.
My primary use case here (and why I can’t just look at the :t
value) is memoizing functions of the db value; since a db value is a value, and is immutable, then it should be able to be a param of a memoized fn. All of my code written this way works correct when connected to dev-local, but when deployed to an ion does not work as intended.