How can I get a snapshot of the current query in R...
# room
p
How can I get a snapshot of the current query in Room instead of a Flow? I need to get the query but not to update the UI if the room database changes before I press the "update" button. Now I got this:
Copy code
val uiState: StateFlow<BusStopsDBScreenUiState> = busDataRepository.getBusStops()
    .map<List<BusStop>, BusStopsDBScreenUiState> { busStops ->
        BusStopsDBScreenUiState.Success(busStops, Res.string.bus_stops_db_filled)
    }
    .catch { throwable ->
        emit(BusStopsDBScreenUiState.Error(throwable))
    }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), BusStopsDBScreenUiState.Loading)
getBusStops returns a flow
Copy code
@Query("SELECT * FROM BusStops")
fun getBusStops(): Flow<List<BusStopEntity>>
s
You can simply change the return type of the Query function and Room will generate a function of that type. For example,
fun getBusStopsSnapshot(): List<BusStopEntity>
would get you a single, non-reactive result.
p
thanks!