Datomic - union between objects that have no reference

My question is, is there a way to combine two objects in a Dataomic that are not referenced in the schema without having to resort to writing two nested iterators (manual concatenation).

In Datomic Doco - they give an example of a request specifying two parameters .

[:find ?n ?u
 :where
 [?c :community/name ?n]
 [?c :community/url ?u]]

      

They call it 'join' - because the underlying structure is a keyed database, so even the attributes of the same object must be joined together.

They then give an example of a connection between two entities that have a link (assuming the link is defined in a schema not shown here):

[:find ?c_name
 :where
 [?c :community/name ?c_name]
 [?c :community/neighborhood ?n]
 [?n :neighborhood/district ?d]
 [?d :district/region :region/ne]]

      

My question is a question similar to the one above with no link in the schema? Or will I have to resort to writing an iterator and pull in the results?

+3


source to share


1 answer


Any variable that occurs more than once in the: where clause is forcibly concatenated.

So you can query for names belonging to the community as well as the neighboring



(def results (q '[:find ?name :where [_ :neighborhood/name ?name] 
                                     [_ :district/name ?name]] 
                 (db conn)))

      

Is this what you asked for? (ids are simply ignored in this example)

+2


source







All Articles