Reputation: 197
I'm going to create SQL view in android. I know for this purpose I should use this syntax in my DAO file:
@DatabaseView("Select Name, Address From Customer")
data class UserInfoView(
val name: String,
val address: String
)
and change my database class like this:
@Database(
entities = [CustomerTable::class],
views = [CustomerDAO.UserInfoView::class],
version = 1,
exportSchema = false
)
but I have no idea how to use this view! in SQL the views work just like tables but how can I use this view in android?
Upvotes: 1
Views: 362
Reputation: 4039
You can use Database View
just as you use an Entity
in DAO
.
@Dao
interface MyDao {
@Query("SELECT * FROM UserInfoView")
fun getUserInfo(): List<UserInfoView>
}
You can not do INSERT
, UPDATE
, and DELETE
operations with Database View. I couldn't find an example in Android
documentation for accessing the View
. So, please check this example for getting more info on this.
Upvotes: 2