Move query generation to the Data class

Also return an empty array instead of running the query