Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity API not available when Datalevin is run as a Babashka pod #283

Open
teodorlu opened this issue Oct 9, 2024 · 0 comments
Open

Entity API not available when Datalevin is run as a Babashka pod #283

teodorlu opened this issue Oct 9, 2024 · 0 comments

Comments

@teodorlu
Copy link

teodorlu commented Oct 9, 2024

Hi!

From my testing, it appears the Datomic Entity API is not available when running Datalevin as a Babashka pod.

I'm interested in using the entity API from a Babashka script because I'd like to use a Datalevin database for keeping my shell script state instead of an EDN file, and I'd like to extract data with the entity API.

Datalevin version: datalevin/datalevin {:mvn/version "0.9.10"}

Different behavior between JVM datalevin and Babashka pod datalevin

Datalevin as Babashka pod:

  (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"}

Datalevin on JVM:

  (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"}

References

Discussed on Slack in September 2024: https://clojurians.slack.com/archives/C01RD3AF336/p1726228973547099

@huahaiy huahaiy added bug Something isn't working and removed bug Something isn't working labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants