Fork me on GitHub
#datascript
<
2024-03-22
>
Nik02:03:43

Hi, I'm learning datalog and datascript. I tried to use example from https://github.com/kristianmandrup/datascript-tutorial/blob/master/pull_data.md When I try same query (in clojure project). I get error

(d/pull-many (d/db conn) '[*] (d/q '[:find ?e :where [?e]]
                                   ))
;; Error - Too few inputs passed, expected: [$], got: 0
When I pass db to inner query
(d/pull-many (d/db conn) '[*] (d/q '[:find ?e :where [?e]]
                                   (d/db conn)))
;; Error - Lookup ref should contain 2 elements: [100]
which I think is happening as result set looks like #{[4] [5] [100]} . If it change to vector and flatten (flatten (vec ids)) and pass it to pull-many then it works. Is there a mistake in guide or am I missing something that will let me chain query to pull expression?

👍 1
Nik04:03:05

In simple todo app. How to write query to find todos which have only 2 tags. would it something like this?

(d/q '[:find ?todo
         :where
         [?todo :tags ?t]
         [(= 2 (count ?t))]])