Fork me on GitHub
#cljsrn
<
2020-01-03
>
Quest07:01:01

(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?

thheller10:01:12

@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

👍 4
Quest11:01:46

@thheller That did the trick. Your memory was correct, someone was kind enough to link me https://github.com/tonsky/datascript/wiki/Tips-&amp;-tricks#externs-and-shadow-cljs which suggests the same tweak. Thank you 🙇

👍 4