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?I suppose https://github.com/tonsky/datascript/wiki/Tips-&-tricks#externs-and-shadow-cljs is the most likely explanation and solution
> There are situations where you will find queries running find under dev but curiously failing under :advanced compilations mode
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
awesome, glad to hear it ^^
does anyone have or know of a public non-trivial datascript db together with non-trivial queries over it?
I guess it doesn't need to be a datascript db, a datalog one would do just as well
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
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
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
oh that's cool
I wonder if everything there is supported by datascript itself
but yeah that has both queries and the database itself
cheers!