datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
2020-05-20T22:26:48.040500Z

Is it possible to pass a db into a rule? As a very simple example, I have this query:

(let [db0 (d/db-with (d/empty-db) [{:name "Mark" :color :red}])
      db1 (d/db-with (d/empty-db) [{:first-name "Mark" :food :pizza}])
      db2 (d/db-with (d/empty-db) [{:src :name :dst :first-name}])]
  (d/q
    '[:find ?n ?c ?f
      :in $0 $1 $2
      :where
      [$0 ?e ?src-key ?n]
      [$0 ?e :color ?c]
      [$2 ?m :src ?src-key]
      [$2 ?m :dst ?dst-key]
      [$1 ?t ?dst-key ?n]
      [$1 ?t :food ?f]]
    db0 db1 db2))
I want to capture the src/dst mapping as a rule, basically using db2 to hold the relationships between db0 and db1. I tried the following approach without success:
(let [db0 (d/db-with (d/empty-db) [{:name "Mark" :color :red}])
      db1 (d/db-with (d/empty-db) [{:first-name "Mark" :food :pizza}])
      db-join (d/db-with (d/empty-db) [{:src :name :dst :first-name}])]
  (d/q
    '[:find ?n ?c ?f
      :in $0 $1 $2 %
      :where
      [$0 ?e ?src-key ?n]
      [$0 ?e :color ?c]
      (rosetta-stone $2 ?src-key ?dst-key)
      [$1 ?t ?dst-key ?n]
      [$1 ?t :food ?f]]
    db-join
    db0
    db1
    '(((rosetta-stone $ ?src-key? dst-key)
       [$ ?e :src ?src-key]
       [$ ?e :dst ?dst-key]))))
This results in:
Execution error (ExceptionInfo) at datascript.parser/parse-rule-expr (parser.cljc:462).
Cannot parse rule-expr arguments, expected [ (variable | constant | '_')+ ]
I've tried a couple different permutations of this to no effect. Any ideas? Thanks!