datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Quest 2020-01-03T07:41:28.006400Z

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 Silva 2020-01-03T11:04:05.006800Z

I suppose https://github.com/tonsky/datascript/wiki/Tips-&-tricks#externs-and-shadow-cljs is the most likely explanation and solution

👍 1
Filipe Silva 2020-01-03T11:04:21.007400Z

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

Quest 2020-01-03T11:28:56.008800Z

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

👍 1
Filipe Silva 2020-01-03T11:36:49.009300Z

awesome, glad to hear it ^^

Filipe Silva 2020-01-03T11:38:02.010400Z

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

Filipe Silva 2020-01-03T11:38:22.010900Z

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

Filipe Silva 2020-01-03T11:39:20.012Z

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

Quest 2020-01-03T11:54:09.014200Z

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

Quest 2020-01-03T11:56:19.015800Z

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 Silva 2020-01-03T12:05:58.016500Z

oh that's cool

Filipe Silva 2020-01-03T12:10:38.016800Z

I wonder if everything there is supported by datascript itself

Filipe Silva 2020-01-03T12:10:51.017300Z

but yeah that has both queries and the database itself

Filipe Silva 2020-01-03T12:10:52.017500Z

cheers!

🍻 1