前回の続き

@Query("SELECT * FROM table_name WHERE package_name LIKE '%' || :query || '%' OR column_name LIKE '%' || :query || '%' ORDER BY CASE WHEN :isDescending = 0 THEN column_name END ASC, CASE WHEN :isDescending = 1 THEN column_name END DESC")
suspend fun search(query: String, isDescending: Boolean): List<Entity>

isDescending==trueの場合はcolumn_nameの降順、isDescending==falseの場合はcolumn_nameの昇順になります。

参考:https://stackoverflow.com/questions/55297165/room-dao-order-by-asc-or-desc-variable