Fork me on GitHub
Nedeljko Radovanovic15:06:51

Hello everyone 👋 I am currently working on a small project and i need help with something.. I want to stack my queries...

(defn users
     (users db nil))
    ([db {:keys [cond]}]
     (let [q (cond->
               '{:find  [(pull ?eid [*])]
                 :where [[?eid :user/created]]}
               (map? cond) (concat (map (partial cons '?eid) cond)))]
       (map first (d/q q db)))))
Here is test for this:
(let [cond {:user/firstname "dummy-value" :user/region :dummy-value}
      q (cond->
          '{:find  [(pull ?eid [*])]
            :where [[?eid :user/created]]}
          (map? cond) (concat (map (partial cons '?eid) cond))]

;; ([:find [(pull ?eid [*])]] [:where [[?eid :user/created]]] (?eid :user/firstname "dummy-value") (?eid :user/region :dummy-value))                  THIS IS MY RETURN VALUE ( BAD )
;; {:find [(pull ?eid [*])] :where [[?eid :user/created] [?eid :user/firstname "dummy-value"] [?eid :user/region :dummy-value]]}                      THIS IS RETURN VALUE I WANT ( GOOD )
I am kind of stuck here 😓 Any reference to a documentation or suggestion will help.. Thank you in advance..


You’re using “map” on a map. I think you meant something like (update :where into (map #(into ['?eid] %)) cond)


try using let only instead of cond-> so that the intermediates are named and it’s less “clever”. I think the mistake will be more obvious.

Nedeljko Radovanovic17:06:00

Thank you very much. 😊