SQL Converter to Mongo Query
The MongoSqlQueryHolder provides a way to convert a SQL query to a Mongo query and execute it on a Mongo database.
Usage
Initialize the query holder with the SQL query you want to analyse or execute.
val queryConverter = MongoSqlQueryHolder("select count(*) as anz from people where age < 30 and (age < 30 or age > 30) order by id asc")
In most cases you simply want to run the query and get the result as a Seq[Document]
.
TIP
The method run returns a classical MongoDb Observable use the implicits to convert it to a Seq[Document]
.
val selectResponse = queryConverter.run(TestDatabase.provider).resultList()
You can also get the information about the collection and the keys that are used in the query.
queryConverter.getCollection mustEqual "people"
queryConverter.getKeysForEmptyDocument mustEqual Set("anz")
In some cases you need the information about the function calls in the query, for example in your own jdbc driver implementation. Because the difference of MongoDb and SQL for example a sql select count(*) from empty-collection
is a list documents with one element and the MongoDb has no document in it.
queryConverter.hasFunctionCallInSelect mustEqual true