0

I am looking to write dynamic queries for an ArangoDB graph database and am wondering if there are best practices or standard approaches to doing it.

By 'dynamic queries' I mean that users would have the ability to build a query that is then executed on the dataset.

Methods that ArangoDB can support this could include:

  • Dynamically generate AQL queries by manually injecting bindvars
  • Write Foxx functions to deliver on supported queries, and have another Foxx function bind those together to build a response.
  • Write a workflow which extracts data into a temporary collection and then invokes Foxx functions to filter/sort the data to the desired outcome.

The queries would be very open ended, where someone would (for example):

  • Query all countries with population over 10,000,000
  • Sort countries by land in square kilometers
  • Pick the top 10 countries in land coverage
  • Select primary language spoken in each country
  • Count occurrences of each language.

That query alone is straight forward to execute, but if a user was able to [x] check or select from a range of supported query options, order them in their own defined way, and receive the output, it's a little more involved.

Are there some supported or recommended approaches to doing this?

My current approach would be to write blocks of AQL that delivered on each part, probably in a LET Q1 = (....), LET Q2 = (...) format, and then finally in the bottom of the query have a generic way of processing the queries to generate a response.

But I have a feeling that smart use of Foxx functions could help here as well, having Foxx-Query-Q1 and Foxx-Query-Q2 coded to support each query type, then an aggregation Foxx app that invoked the right queries in the right order to build the right response.

If anyone has seen best ways of doing this, it would be great to get some hints/advice.

Thanks!

David Thomas
  • 2,264
  • 2
  • 18
  • 20
  • Did you consider the use of the ArangoDB Query Builder? https://github.com/arangodb/aqbjs – CodeManX Sep 20 '16 at 12:15
  • Yes, thanks for that link. My concern (and I'll have to test it) is that the chaining of queries is performed at the client end, not aggregated into a single query and executed at the server end. The other issue is how to customise the chain before it's sent. I may end up writing an AQL generator, forcing the complete custom query to be executed server side. – David Thomas Sep 21 '16 at 09:05
  • AQB creates data structures, which can eventually be turned into a string of AQL and executed on the server. You can use AQB server-side too, using Foxx. But given the broad spectrum of queries you want to allow, maybe it's easier to construct AQL queries client-side (even handwritten would be possible for maximum flexibility) and pass them through a Foxx endpoint, which can retrieve the AST for the query and ensure that no data modifications or other unwanted operations are contained in the query? – CodeManX Sep 21 '16 at 10:39

0 Answers0