Fork me on GitHub
#datomic
<
2022-02-08
>
kipz11:02:17

Hi all. I'm having a problem querying through time! Any help much appreciated. Say I want to pass two databases to some query. One is the current database $ and one is before $before. This seems to work for some simple clauses:

[$before ?version :vulnerability.advisory.version/vulnerable-range ?range]
but using or-join for example:
(or-join [?version ?range]
     [$before ?version :vulnerability.advisory.version/vulnerable-range ?range])
we get an error:
{:cognitect.anomalies/category :cognitect.anomalies/incorrect,
 :cognitect.anomalies/message
 "processing clause: [$before ?version :vulnerability.advisory.version/vulnerable-range ?range], message: Cannot resolve key: $before"}
I've tried passing the database in arguments to the or-join, but the error is similar:
{:cognitect.anomalies/category :cognitect.anomalies/incorrect,
 :cognitect.anomalies/message
 "processing clause: [$before ?version ?range], message: Cannot resolve key: $before"}
Am I doing something wrong here? Is there another way to pass databases around?

Linus Ericsson12:02:35

According to the documentation the syntax for or-join is: or-join-clause = [ src-var? 'or-join' rule-vars (clause | and-clause)+ ] so maybe try

($before or-join [?version ?range]
     [?version :vulnerability.advisory.version/vulnerable-range ?range])

Lennart Buit12:02:38

if you name your rule, you can pass it before the rule name:

($my-database rule ?arg ?arg2 ?arg2)

Lennart Buit12:02:45

but you can never pass more than one database value to a rule

kipz13:02:04

@UDF11HLKC thanks, but I'm not using a rule here (at least not one I can control)

Lennart Buit13:02:58

You are, or-join is just an anonymous rule; so the same limitation counts for the syntax Linus shared

kipz13:02:26

The problem is that I need a different database for different clauses of the or-join - hence my attempt there. Sounds like I need to create my own function to do this.

Linus Ericsson13:02:04

Yes, I think that will need a separate function or separate queries.

kipz13:02:31

Thanks again both.