Can data source substituted dynamically?

Can I somehow calculate src-var? dynamically right in query for data-pattern( [ src-var? (variable | constant | ‘_’)+ ])

I’m trying to achieve something like in the next simplified example

(defn chooseDb [db] db)

(d/q '[:find
 ?e
 :in $
 :where
 [(user/chooseDb $) $dbToUse]
 [$dbToUse ?e :someAttr]
]
(d/db conn))

Attempting to execute the above code leads to

Execution error (IllegalArgumentException) at datomic.query/move-sources-to-meta$fn (query.clj:288).
Data source not supplied: $dbToUse
2 Likes

Is it impractical in your use-case to do this as a separate query and then pass the correct DB as an arg to this query?

We have entities which have references as string values(some key values which can be used to reference entities from other datomic databases) on entities from other datomic databases, so it might be different DB depending on reference value