Improve where handling in DatabaseConnection