For example, your entity:
@Entity(tableName = "articles") public final class Article { @PrimaryKey public long serverId; public String title; public String url; public boolean isSubscribed; }
You can write this method in DAO:
@Query("INSERT OR REPLACE INTO articles (serverId, title, url, isSubscribed) VALUES (:id, :title, :url, COALESCE((SELECT isSubscribed FROM articles WHERE id = :id), 0));") void insertOrUpdateArticle(long id, String title, String url);
Another option is to write this logic in your repository and use two simple operations: select and update
source share