Fork me on GitHub
#datomic
<
2021-07-23
>
fabrao00:07:31

Hello all, what is the problem with that?

(d/q '[:find ?e ?id :where [?e :user/id ?id]] (-> @system :system.component.datomic/db))
; Execution error (Exceptions$IllegalArgumentExceptionInfo) at datomic.error/arg (error.clj:57).
; :db.error/invalid-data-source Nil or missing data source. Did you forget to pass a database argument?

fabrao00:07:42

#:datomic{:conn #object[datomic.peer.LocalConnection 0x6ae42d2d "datomic.peer.LocalConnection@6ae42d2d"]} <- for (-> @system stuff ...

jaret01:07:53

@fabrao Looks like you are missing a DB.

jaret01:07:24

(def db (d/db conn))
(d/q '[:find ?e ?id :where [?e :user/id ?id]] db)

denik13:07:26

How does one exclude values in a collection binding? this does not work:

(db/q '[:find [?m ...]
        :in $ [?ignore-ids ...]
        :where
        [?m :mom-rec-id ?mid]
        (not [?m :mom-rec-id ?ignore-ids])]
      #{"ignored" "ids"})

refset14:07:33

Have you tried a contains? predicate like this instead of the not clause: [(clojure.core/contains? ?ignore-ids ?mid)] ?

denik14:07:38

yes using functions works, I also passed in the complemented set and used it as a function

denik14:07:09

just surprised that there doesn’t seem to be an idiomatic way to do negation

denik14:07:35

also since I’m using the collection binding the contains? code would actually break

refset14:07:02

hmm, I think you want to use Datalog-native unification like this then

(db/q '[:find [?m ...]
        :in $ [?ignore-ids ...]
        :where
        [?m :mom-rec-id ?mid]
        [(!= ?m ?ignore-ids)]
      #{"ignored" "ids"})

souenzzo17:07:43

I had a issue with this kind of queries and end up writing:

:in $ ?ignore
:where
[?m :mom-rec-id ?mid]
[(contains? ?ignore ?mid) ?q]
[(ground false) ?q]
https://gist.github.com/souenzzo/c7b5a5434d4c04efcc58802c81b46023

denik17:07:38

@U899JBRPF tried that and it didn’t work for me

denik17:07:44

could also be a bug in datascript

refset18:07:37

oh, yeah, maybe datascript doesn't support it...I was looking at Crux's tests for inspiration 😅 https://github.com/juxt/crux/blob/065db71c9f6f4c3a3c2d2eb75916bb15c719f75b/crux-test/test/crux/query_test.clj#L1008-L1011 - I can't see an equivalent test in datascript's suite, and looking at the source it seems datascript maps != to not= which is not really the same thing imo I guess that kind of unification logic is ~impractical without a query planner (sorry for the noise!)