(Reposting from #datascript, hoping someone here may recognize this.) Ran into a very bizarre case. After compiling React-Native (Expo) app with shadow-cljs, datascript queries return nothing or very strange results
;; require
[datascript.core :as ds-db]
(let [test-db (db/create-conn {:id {:db/index true
:db/cardinality :db.cardinality/one}})
tx (db/transact test-db [{:id 1
:text "this is a test"}])
query (db/q '[:find ?text
:in $
:where
[?e :id 1]
[?e :text ?text]]
(db/db test-db))]
(println "test-db=" test-db)
(if-not (= query "this is a test")
{:result :failed
:query-return query}
{:result :success
:query-return query}))
Failed return (on latest datascript 0.18.8
):
test-db= #object[cljs.core.Atom {:val #datascript/DB {
:schema {:id {:db/index true, :db/cardinality :db.cardinality/one}},
:datoms [[1 :id 1 536870913] [1 :text "this is a test" 536870913]]}}]
{:result :failed, :query-return #{[2162164496]}}
Note the strange return value of #{[2162164496]}
.
However, running it in development mode produces the expected query-return of #{[this is a test]}
Anyone have a theory about why this is happening or what the returned value is?@quest I think datascript requires manual externs. can't remember the details but I think including :compiler-options {:externs ["datascript/externs.js"]}
in your build config fixes it
@thheller That did the trick. Your memory was correct, someone was kind enough to link me https://github.com/tonsky/datascript/wiki/Tips-&-tricks#externs-and-shadow-cljs which suggests the same tweak. Thank you 🙇