title: Room database Insert or update but keep a database field?
body: <p>I am trying to achieve the following scenario -> Records are fetched from API and stored into DB. Some of the records might be clicked as <code>favorite</code> and they should stay like that even if new data is fetched from API. But, I can't seem to find a way on how to not replace those records that already have been selected as <code>favorite</code> without replacing the whole row. I've tried inserting the records one by one and somehow in that insertion check if a record already exists but I can't seem to figure it out using RxJava.</p>
  
  <p><code>Dao</code></p>
  
  <pre><code>    @Dao
      interface KafanaDao {
  
      @Insert
      fun insertSingleKafana(kafana: Kafana)
  
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      fun insertAll(kafani: List&lt;Kafana&gt;)
  
      @Query("SELECT * FROM ${Constants.KAFANI_TABLE_NAME}")
      fun getKafani(): Single&lt;List&lt;Kafana&gt;&gt;
  
      @Query("SELECT * FROM ${Constants.KAFANI_TABLE_NAME} WHERE name = :name")
      fun getSingleKafana(name: String): Single&lt;Kafana&gt;
  
      @Query("UPDATE ${Constants.KAFANI_TABLE_NAME} SET isFavorite = :isFavorite WHERE name = :name")
      fun setFavourite(name: String, isFavorite: Int)
  }
  </code></pre>
  
  <p>Then I keep inserting the records one by one, but how do I check if they are already stored in the database?</p>
  
  <pre><code>fun insertSingleKafanaInDb(kafana: Kafana) {
      Observable.fromCallable { kafanaDao.insertSingleKafana(kafana) }
              .subscribeOn(Schedulers.io())
              .subscribe {
                  Timber.d("Inserted ${kafana.name} kafani from API in DB...")
              }
  }
  
  fun getKafaniFromApi(): Observable&lt;List&lt;Kafana&gt;&gt; {
      return apiService.getKafani().toObservable().doOnNext {
          for (kafana in it) {
              //I need to somehow do the check here
              insertSingleKafanaInDb(kafana)
          }
      }
  }
  </code></pre>
  
  <p><code>Entity</code></p>
  
  <pre><code>    @Entity(tableName = Constants.KAFANI_TABLE_NAME)
      data class Kafana(
          @PrimaryKey
          @ColumnInfo(name = "name")
          @SerializedName("name")
          val name: String,
          @ColumnInfo(name = "phone")
          @SerializedName("phone")
          val phone: String,
          @ColumnInfo(name = "address")
          @SerializedName("address")
          val address: String,
          @ColumnInfo(name = "city")
          @SerializedName("city")
          val city: String,
          @ColumnInfo(name = "sponsored")
          @SerializedName("sponsored")
          val isSponsored: Boolean,
          @ColumnInfo(name = "isFavorite")
          var isFavorite: Boolean
  
  )
  </code></pre>