Skip to content

Instantly share code, notes, and snippets.

@objcode
Created May 21, 2019 01:50
Show Gist options
  • Save objcode/c600bf47b5f801c4e014c47494ff6f3e to your computer and use it in GitHub Desktop.
Save objcode/c600bf47b5f801c4e014c47494ff6f3e to your computer and use it in GitHub Desktop.
Implement a one shot request with coroutines (@dao)
@Dao
interface ProductsDao {
// Because this is marked suspend, Room will use it's own dispatcher
// to run this query in a main-safe way.
@Query("select * from ProductListing ORDER BY dateStocked ASC")
suspend fun loadProductsByDateStockedAscending(): List<ProductListing>
// Because this is marked suspend, Room will use it's own dispatcher
// to run this query in a main-safe way.
@Query("select * from ProductListing ORDER BY dateStocked DESC")
suspend fun loadProductsByDateStockedDescending(): List<ProductListing>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment