DatabaseView
public
abstract
@interface
DatabaseView
implements
Annotation
| androidx.room.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")
public class SongFrom90s {
long id;
String name;
@ColumnInfo(name = "release_year")
private int releaseYear;
}
Views have to be registered to a RoomDatabase via Database.views().
See also:
Summary
Public methods | |
|---|---|
String
|
value()
The SELECT query. |
String
|
viewName()
The view name in the SQLite database. |
Inherited methods | |
|---|---|
Public methods
value
public String value ()
The SELECT query.
| Returns | |
|---|---|
String |
The SELECT query. |
viewName
public String viewName ()
The view name in the SQLite database. If not set, it defaults to the class name.
| Returns | |
|---|---|
String |
The SQLite view name. |