Created
June 2, 2022 06:38
-
-
Save abdulhafizramadan-ittp/17ffc5486f24b7cd8265130489c97185 to your computer and use it in GitHub Desktop.
Android | Query a Raw in Room that return a LiveData<Boolean>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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