I'm trying to learn how datascript/datomic rules work.
(def conn (ds/create-conn {}))
(ds/transact! conn
[{:id 1 :size 2}
{:id 2 :size 3}])
(def query '[:find ?size
:in $ % ?id
:where
(size ?id ?size)])
(ds/q query (ds/db conn)
'[[(size ?id ?size)
[?x :id ?id]
[?x :size ?size]]]
1)
;;returns #{[2]} (expected)
(ds/q query (ds/db conn)
'[[(size [?id] ?size) ;; require id be bound by enclosing in vector
[?x :id ?id]
[?x :size ?size]]]
1)
;; returns #{[3] [2]}. not sure why.
Why does requiring the ?id variable be bound in the rule definition prevent the results from being narrowed with the ?id I'm passing in to the query?Just ran into this issue. I’ve opened a ticket here: https://github.com/tonsky/datascript/issues/441
You know what, I don’t think we support this. There’s some work in the parser but it’s not used in current query impl. There are no tests on this either
Weird, probably a bug
I didn’t even know could do in-line rule queries like that 🤔
Oh I see
@jjttjj what happens if you transact 3 diatoms there. Do you get all 3 back? If so, maybe [?id] is resolving truthy? Just a wild guess