I'm trying to make a @Query
function in my @Dao
interface which has a boolean parameter, isAsc
to determine the order:
@Query("SELECT * FROM Persons ORDER BY first_name (:isAsc ? ASC : DESC)")
List<Person> getPersonsAlphabetically(boolean isAsc);
Apparently this isn't allowed. Is there a work around here?
EDIT:
It seemed odd to use two queries (below) since the only difference is ASC
and DESC
:
@Query("SELECT * FROM Persons ORDER BY last_name ASC")
List<Person> getPersonsSortByAscLastName();
@Query("SELECT * FROM Persons ORDER BY last_name DESC")
List<Person> getPersonsSortByDescLastName();