Last active
June 1, 2021 16:59
-
-
Save barbeau/2fb71a96e0ff22c2c356acca7d159901 to your computer and use it in GitHub Desktop.
Medium article - Room + Flow for location updates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface LocationDao { | |
@Transaction | |
suspend fun updateLocation(location: Location) { | |
location.let { | |
deleteLocations() // This deletes previous locations to keep the database small. If you want to store a full location history, remove this line. | |
insertLocation(it) | |
} | |
} | |
@Insert(onConflict = OnConflictStrategy.IGNORE) | |
suspend fun insertLocation(location: Location) | |
@Query("DELETE FROM location_table") | |
suspend fun deleteLocations() | |
@Query("SELECT * FROM location_table ORDER BY time") | |
fun getLocations(): Flow<List<Location>> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment