ribelo / doxa

The Unlicense
232 stars 8 forks source link

runtime query args? #14

Closed stevebuik closed 3 years ago

stevebuik commented 3 years ago

I guess this is similar to https://github.com/ribelo/doxa/issues/5

(let [db (dx/create-dx [{:db/id 1, :name "Ivan" :age 15}
                        {:db/id 2, :name "Petr" :age 37}])
      age 15]
  [; returns a value
   (dx/q [:find ?name
          :in ?age
          :where
          [?e :name ?name]
          [?e :age ?age]]
         db 15)
   ; does not return a value
   (dx/q [:find ?name
          :in ?age
          :where
          [?e :name ?name]
          [?e :age ?age]]
         db age)])

Does this mean that the only value that can be used as runtime args to dx/q is the db value?

Is it possible for runtime args to work while still using meander? Or is the answer the same as for #5 ?

I want to know so I can explain this properly in my sample application

spacegangster commented 3 years ago

@stevebuik same in ClojureScript for me.

I've found a workaround:

(let [db (dx/create-dx [{:db/id 1, :name "Ivan" :age 15}
                        {:db/id 2, :name "Petr" :age 37}])
      age2 15]
  [; returns a value
   (dx/q [:find ?name
          :in ?age
          :where
          [?e :name ?name]
          [?e :age ?age]]
         db 15)

   ; workaround
   (dx/q [:find ?name
          :in ?ageee
          :where
          [?e :name ?name]
          [?e :age ?age]
          [(= ?age ?ageee)]]
         db age2)])
stevebuik commented 3 years ago

interesting. I have been testing this on the jvm and that workaround didn't work there. I wonder if this behaves differently on clj vs cljs?

ribelo commented 3 years ago

The fact that it doesn't work as an argument after the db on jvm is a bug. It worked, but there was no test so it got messed up somewhere. I'll fix it today. When it comes to using arguments inside the query, put a tilde in front of the variable

(let [db (dx/create-dx [{:db/id 1, :name "Ivan" :age 15}
                        {:db/id 2, :name "Petr" :age 37}])
      age 15]
  (dx/q [:find ?name
         :where
         [?e :name ?name]
         [?e :age ~age]]
    db))
;; => [["Ivan"]]
ribelo commented 3 years ago

Fixed.

stevebuik commented 3 years ago

thanks. closing this one.