DatabaseView



Marks a class as an SQLite view.

The value of the annotation is a SELECT query used when the view is created.

The class will behave like normal POJO when it is used in a Dao. You can SELECT FROM a DatabaseView similar to an Entity, but you can not INSERT, DELETE or UPDATE into a DatabaseView.

Similar to an Entity, you can use ColumnInfo and Embedded inside to customize the data class.

Example:

@DatabaseView(
"SELECT id, name, release_year FROM Song " +
"WHERE release_year >= 1990 AND release_year <= 1999"
)
data class SongFrom90s (
val id: Long,
val name: String,
@ColumnInfo(name = "release_year")
val releaseYear: Int
)

Views have to be registered to a RoomDatabase via Database.views.

Summary

Public constructors

DatabaseView(value: String, viewName: String)
Cmn

Public properties

String

The SELECT query.

Cmn
String

The view name in the SQLite database.

Cmn

Public constructors

DatabaseView

DatabaseView(value: String = "", viewName: String = "")

Public properties

value

val valueString

The SELECT query.

Returns
String

The SELECT query.

viewName

val viewNameString

The view name in the SQLite database. If not set, it defaults to the class name.

Returns
String

The SQLite view name.