Fork me on GitHub
#datascript
<
2020-08-18
>
charlie engelhard15:08:44

Hi, I'm getting started with datascript and I'm confused at what is probably a dumb newbie error. I have a query expression

(d/q '[:find ?t :where [?t :tile/pop ?p] (< 0 ?p)] db)
where 'db' is a db value. I want to get all entities with a :tile/pop greater than 0. I'm getting an error that says "Missing rules var '%' in :in". I don't believe that I really need an :in here at all. But if I add ":in %", I get another confusing error "Don't know how to create ISeq from: clojure.lang.Keyword". I'm not really sure how to interpret these errors.

Braden Shepherdson16:08:25

and just a shot in the dark, but maybe try (> ?p 0) instead?

Braden Shepherdson16:08:39

the first error indicates that writing conditions like (< ...) needs a "rules" collection passed in. that means including, at minimum the database (`$`) and rules (`%`) in :in $ % and as arguments in the same order.

Braden Shepherdson16:08:05

but < and > should be built-in and not need a rules object. at least that's how it works in Datomic; I'm not sure about DataScript.

zane16:08:42

> In ClojureScript, custom query functions and aggregates should be passed as source instead of being referenced by symbol (due to lack of `resolve` in CLJS) > — https://github.com/tonsky/datascript#project-status @ochuckles Probably this? ☝️:skin-tone-2: Try something like:

(d/q '[:find ?t
       :in $ ?<
       :where
       [?t :tile/pop ?p]
       [(?< 0 ?p)]]
     db
     <)
EDIT: Probably not this! See @encube.ul’s comment below.