Convert a query object to a CouchDB compatible query string