Database can't be passed explicitly for or/or-join clauses

Hi, when I’m trying to use database in datoms inside or/or-join clauses then datomic throws

Cannot resolve key: $

The query is:

(d/q "[
  :find [?user ...] 
  :in $
  :where 
    (or
        [$ ?user :user/name \"Boby\"] 
        [$ ?user :user/name \"Boby\"]
     )
 ]" (d/db conn))

More interesting things, if to name database using another name:

(d/q "[
  :find [?user ...] 
  :in $someDb
  :where 
    (or
      [$someDb ?user :user/name \"Boby\"] 
      [$someDb ?user :user/name \"Boby\"]
     )
     
 ]" (d/db conn))

Then the response is:

Execution error (Exceptions$IllegalArgumentExceptionInfo) at datomic.error/arg (error.clj:79).
:db.error/invalid-data-source Nil or missing data source. Did you forget to pass a database argument?

Okay, let’s pass default DB too, then the same issue but about $someDb:

(d/q "[
  :find [?user ...] 
  :in $ $someDb
  :where 
    (or
      [$someDb ?user :user/name \"Boby\"] 
      [$someDb ?user :user/name \"Boby\"]
     )
     
 ]" (d/db conn) (d/db conn))
Execution error (IllegalArgumentException) at datomic.datalog/resolve-id (datalog.clj:273).
Cannot resolve key: $someDb

But all works fine if to execute and join even passing only one DB using custom name

(d/q "[
  :find [?user ...] 
  :in $someDb
  :where     
      [$someDb ?user :user/name \"Boby\"] 
      [$someDb ?user :user/name \"Boby\"]
 ]" (d/db conn)) 

Then a success response is returned.

So looks like or join is hardly tied to $ and can’t accept database source passed explicitly .

P.S. Doc says

or clauses target a source named $ unless you specify an explicit src-var .

Datomic: On-Prem:0.9.6045

i think docs say src-var is defined at the OR level, not the nested stmt level

Oh I got, thanks for pointing me to understand what is wrong. Actually my main case is to use different databases in OR-clauses but I see doc says: As with rules, *src-vars* are not currently supported within the clauses of *or* , but are supported on the *or* clause as a whole at top level. and I found something on the internet: https://datomic.narkive.com/H6z769jM/multiple-databases-in-or and on the forum: Rules with multiple data sources?

Query I’m interesting is:

(d/q "[
  :find [?user ...] 
  :in $ $someDb
  :where 

(or-join [?user]

  (and
    [$someDb _ :user/name ?externalName1] 
    [$ ?user :user/name.EN ?externalName1]
  )

  (and
      [$someDb _ :user/name ?externalName2] 
      [$ ?user :user/name.EN ?externalName2]
   )  
 )   
 ]" (d/db conn) (d/db conn))

And looks like the only possible way is to rearrange query to:

(d/q "[
      :find [?user ...] 
      :in $ $someDb
      :where 

    [$someDb _ :user/name ?externalName1]
    [$someDb _ :user/name ?externalName2] 

    (or-join [?user]
      [?user :user/name.EN ?externalName1]
      [?user :user/name.ES ?externalName2]
    )  

]" (d/db conn) (d/db conn)) 

But first case could be more preferable since if first statement from or is true then second part is not executed what is better from performance point

@marshall Could you please tell whether Datomic team is going to support multiply datasource in or clauses?

I think there may be some problems with the documentation. The grammar says the source var needs to be specified on the OR level, but the grammar looks like this:

or-clause         = [ src-var? 'or' (clause | and-clause)+]

There are no parenthesis in here for the OR clause, so it’s unclear exactly how to form a query from this - as in, where do the parenthesis go relative to the source var and ‘or’ literal. Some times things are quoted in the grammar when they are a literal and sometimes not. So it appears ‘…’ implies including the ellipsis but having a [ without quotes also means include the brackets and the absence of parenthesis doesn’t mean they are not needed. Having parenthesis in the grammar means what is within parenthesis are options (contrary to having brackets, which means nothing to the grammar rules and are to be literally included in the code).

I really appreciate having the grammar rules and I consider myself somewhat proficient at reading grammar rules, but it seems these rules lack clarity about how to actually generate the code. I believe this is contributing to the confusion here… it is for me at least.