Hi! Is the entity API (`d/entity`) supported when running datalevin from a babashka pod?
done
Maybe YMMV or things have changed, but my recollection of Datomic Free was that an entity's supply of attributes might be incomplete until d/touch. You could force an attribute by querying it (the entity being a somewhat magical Map) or calling d/touch. After all, an entity might involve jillions of datoms, and a program generally does not want to spend time fetching any that it does not directly need.
Amazing, thank you! Looking forward to try it 🙏
(comment
(require '[babashka.fs :as fs]
'[babashka.pods])
(babashka.pods/load-pod 'huahaiy/datalevin "0.9.10")
(require '[pod.huahaiy.datalevin :as d])
(def db-path "/tmp/datalevin/example-pod-entity")
(when (fs/exists? db-path)
(fs/delete-tree db-path))
(def schema {:account/username {:db/valueType :db.type/string
:db/unique :db.unique/identity}
:account/name {:db/valueType :db.type/string}})
(def conn (d/get-conn db-path schema))
(d/transact! conn [{:account/username "teodorlu"
:account/name "Teodor"}])
;; Query appears to work fine
(d/q '[:find ?username ?name
:where
[?e :account/username ?username]
[?e :account/name ?name]]
(d/db conn))
;; => #{["teodorlu" "Teodor"]}
;; Entity isn't doing what I expect!
(select-keys (d/entity (d/db conn) [:account/username "teodorlu"])
[:account/username :account/name])
;; => {}
(into {} (d/entity (d/db conn) [:account/username "teodorlu"]))
;; => {:db/id 1, :db-name #uuid "2934d6d6-2734-4959-b296-547ed76d996e"}
,)Making "lazy entities" work when working with two processes (my script bababashka process and the datalevin process) may be a challenge?
Entity API appears to work as I'd expect when running on a JVM:
;; Datalevin Entity API from JVM
(comment
(set! *print-namespace-maps* false)
(require '[babashka.fs :as fs]
'[datalevin.core :as d])
(def db-path "example-jvm-entity")
(when (fs/exists? db-path)
(fs/delete-tree db-path))
(def schema {:account/username {:db/valueType :db.type/string
:db/unique :db.unique/identity}
:account/name {:db/valueType :db.type/string}})
(def conn (d/get-conn db-path schema))
(d/transact! conn [{:account/username "teodorlu"
:account/name "Teodor"}])
(select-keys (d/entity (d/db conn) [:account/username "teodorlu"])
[:account/username :account/name])
;; => {:account/username "teodorlu", :account/name "Teodor"}
(into {} (d/entity (d/db conn) [:account/username "teodorlu"]))
;; => {:account/username "teodorlu", :account/name "Teodor"}
,)You don't need d/touch to retrieve all the datoms of the entity? (I don't know Datalevlin's entity API)
My expectation is that touch is not needed. Touch appears to not be needed on JVM datalevin (see above). I don't think touch is needed with Datomic either.
You can file an issue. Basically, entity needs to be serialized over the wires. These things take work. PR welcome
@phill very late reply here, but as far as I can tell from the https://docs.datomic.com/reference/entities.html, d/touch appears not to be needed:
Added an issue: https://github.com/juji-io/datalevin/issues/283
@teodorlu You can navigate without having done touch. But if you just print the entity, the printout may reflect only a seemingly-arbitrary subset of datoms. Calling entity does not induce complete retrieval of all datoms related to the entity.