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

Ran into a very bizarre case. After compiling React-Native (Expo) app with shadow-cljs, 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?

Filipe Silva11:01:21

> There are situations where you will find queries running find under dev but curiously failing under :advanced compilations mode

Quest11:01:56

D'oh, that's a good find. Thank you @filipematossilva -- thheller also confirmed this fix. I added the :externs and it works as expected now

👍 4
Filipe Silva11:01:49

awesome, glad to hear it ^^

Filipe Silva11:01:02

does anyone have or know of a public non-trivial datascript db together with non-trivial queries over it?

Filipe Silva11:01:22

I guess it doesn't need to be a datascript db, a datalog one would do just as well

Filipe Silva11:01:20

I'm working on a firebase persistence lib for datascript and wanted to test it by loading said db in several different ways and verifying the queries all returned the same result

Quest11:01:09

Only lead I can think of off the top of my head is the music brainz dataset used for datomic workshops. Might still qualify as trivial, but there's a lot of example queries with documentation and the data is available in EDN https://github.com/Datomic/mbrainz-sample?files=1

Quest11:01:19

actually it looks like the repo author already did the export from EDN to a Datomic backup. You'd have to export it back to EDN & import to datascript, so not particularly convenient

Filipe Silva12:01:58

oh that's cool

Filipe Silva12:01:38

I wonder if everything there is supported by datascript itself

Filipe Silva12:01:51

but yeah that has both queries and the database itself