Skip to content

Instantly share code, notes, and snippets.

@abdulhafizramadan-ittp
Created June 2, 2022 06:38
Show Gist options
  • Select an option

  • Save abdulhafizramadan-ittp/17ffc5486f24b7cd8265130489c97185 to your computer and use it in GitHub Desktop.

Select an option

Save abdulhafizramadan-ittp/17ffc5486f24b7cd8265130489c97185 to your computer and use it in GitHub Desktop.
Android | Query a Raw in Room that return a LiveData<Boolean>
package com.ahr.newsapp.data.local.room
import androidx.lifecycle.LiveData
import androidx.room.*
import com.dicoding.newsapp.data.local.entity.NewsEntity
@Dao
interface NewsDao {
@Query("SELECT EXISTS(SELECT * FROM news WHERE title = :title)")
fun isNewsBookmarked(title: String): LiveData<Boolean>
}
package com.ahr.newsapp.data.local.entity
import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize
@Parcelize
@Entity(tableName = "news")
class NewsEntity(
@field:ColumnInfo(name = "title")
@field:PrimaryKey
val title: String,
@field:ColumnInfo(name = "publishedAt")
val publishedAt: String,
@field:ColumnInfo(name = "urlToImage")
val urlToImage: String? = null,
@field:ColumnInfo(name = "url")
val url: String? = null
) : Parcelable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment