Welcome! Please see the About page for a little more info on how this works.

0 votes
in Libs by

Getting a seemingly bizarre problem with Datascript. For some reason when I run this query without it being wrapped in a function, everything works. But once I wrap it in a function, it returns the value for :block/content for every entity in the database. I'm confused because I haven't encountered any issues with wrapping other Datascript queries in the past. Does anyone more experienced than me with Datascript see any issues?

;; Works fine and returns the correct value
(ds/q '[:find ?block-text
        :where
        [?id :block/id "l_63xa4m1"]
        [?id :block/content ?block-text]]
      @conn)

;; Returns every value for `:block/content` in the db
(defn content-find
  [id-passed]
  (ds/q '[:find ?block-text
          :where
          [?id :block/id ?id-passed]
          [?id :block/content ?block-text]]
        @conn))
(content-find "l_63xa4m1")

1 Answer

+3 votes
by

There is no link between id-passed function argument and ?id-passed symbol in a query, you need to specify that ?id-passed is a query argument and pass it to a query:

(defn content-find
  [id-passed]
  (ds/q '[:find ?block-text
          :in $ ?id-passed
          :where
          [?id :block/id ?id-passed]
          [?id :block/content ?block-text]]
        @conn id-passed))
...