DatabaseView

@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE]) class DatabaseView
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.

Summary

Public constructors

<init>(value: String, viewName: String)

Marks a class as an SQLite view.

Properties

String

The SELECT query.

String

The view name in the SQLite database.

Public constructors

<init>

DatabaseView(value: String, viewName: String)

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.

Properties

value

val value: String

The SELECT query.

Return
String: The SELECT query.

viewName

val viewName: String

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

Return
String: The SQLite view name.