tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.49k stars 309 forks source link

:in argument works with nothing other than $ #72

Closed myguidingstar-zz closed 9 years ago

myguidingstar-zz commented 9 years ago
  (d/q '[:find ?a
         :in $
         :where [?a :foo 1]]
       [[1 :foo 1]])
  ;; => #{[1]}
  (d/q '[:find ?a
         :in $x
         :where [?a :foo 1]]
       [[1 :foo 1]])
  ;; => #{}

datascript.parser/parse-src-var works as expected. I'm not sure where the problem is.

tonsky commented 9 years ago

$ is a default source name. If you omit :in, it assumes :in $. If you don’t specify source in a pattern, it assumes $, e.g. [$ ?a :foo 1].

In your second case you’re using non-default source name in :in, but default in pattern. This should work:

(d/q '[:find ?a
         :in $x
         :where [$x ?a :foo 1]]
       [[1 :foo 1]])