Outer Joins

In the relational database world, outer joins allow you to return a relations even when data is missing from one side of a join. For example, a report from a social networking site might want to list all users, plus the number of items they have upvoted. With an outer join, such a query would return even those users who have not upvoted anything.

In Datomic, there are two ways you can deal with this situation:  by entity navigation or extension function.

The entity navigation approach takes advantage of the fact that Datomic lets you separate query into two logically distinct steps: finding the entities you want, and then navigating to related data. So, continuing the example, you would query for all users in one step, and then use entity navigation to see each user's upvotes, as shown in this example. This decomposition is possible because a Datomic database is a value, not a place.

The extension function approach invokes an extension function inside the query, specifying a default value to return if one side of an implicit join is missing.  This example shows using a maybe method written in Java. 

Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk