Skip to content

Commit

Permalink
Merge pull request #43 from f33lnothin9/dev
Browse files Browse the repository at this point in the history
Sort the categories by their usage
  • Loading branch information
nikbulavin authored Nov 11, 2024
2 parents 7fa3032 + 3f5eaf8 commit 8f5d9ef
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ interface CategoryDao {
@Query("SELECT * FROM categories WHERE id = :id")
fun getCategoryEntity(id: String): Flow<CategoryEntity>

@Query("SELECT * FROM categories ORDER BY id DESC")
@Query(
value = """
SELECT c.id, c.title, c.icon_id FROM categories c
LEFT JOIN (
SELECT tc.category_id, COUNT(tc.category_id) AS usage_count
FROM transactions_categories tc
GROUP BY tc.category_id
) AS usage ON c.id = usage.category_id
ORDER BY usage.usage_count DESC;
""",
)
fun getCategoryEntities(): Flow<List<CategoryEntity>>

@Upsert
Expand Down

0 comments on commit 8f5d9ef

Please sign in to comment.