datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
charlie engelhard 2020-08-18T15:37:44.138600Z

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.

2020-08-18T16:17:31.139100Z

try adding :in $?

2020-08-18T16:18:25.139500Z

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

2020-08-18T16:19:39.140500Z

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.

2020-08-18T16:20:05.141100Z

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.

zane 2020-08-18T16:39:42.142200Z

> 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.