3
votes

Does datomic support subqueries or can those be simulated within a query? That would essentially be a :find within another :find.

I'm trying to perform analytical transformations of data in the query/DB itself rather than in the application.

1
Can you give an example? - Alan Thompson
A SQL example is like [select id, len from (select id, length(foo) as len from user) as t;] So I can create nested tables with an inner select and have transformations in the external select. - rrevo
Do you use the Peer API or the Client API? - Alexander Kiel
I wanted to use the Rest API (which is deprecated.) - rrevo

1 Answers

5
votes

Yes, you can issue a 'subquery' in Datomic. An example is provided here.

It's also worth noting that because the work of query happens in your peer (assuming you're using the Peer API), there is not the same "n+1 problem" penalty for issuing two separate queries as you would have with a traditional RDB. So in addition to the sub-query approach, you could also issue the 'inner' query first, then pass the results from it as parameters to the 'outer' query.

-Marshall