Skip to content

Instantly share code, notes, and snippets.

@barbeau
Last active June 1, 2021 16:59
Show Gist options
  • Save barbeau/2fb71a96e0ff22c2c356acca7d159901 to your computer and use it in GitHub Desktop.
Save barbeau/2fb71a96e0ff22c2c356acca7d159901 to your computer and use it in GitHub Desktop.
Medium article - Room + Flow for location updates
@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