Remove obsolete code of QueryModel.

This was a first approach of implementing database queries but soon proved
to be not flexible enough. Later on it was substituted by
f.database.models.QueryView, although the old code was left for the legacy
code to work. Also some code was shared between the two implementations.
This commit cleans this up and moves all the relevant code to dbmodels
module.
Include total_count property in the response of database query.
Improve efficiency of calculating the result of (sub)query by
dissalowing usage of mixed operators.