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 POJOs when it is used in Dao. You can SELECT from DatabaseView like Entity, but you can not INSERT, DELETE or UPDATE DatabaseView. You can use ColumnInfo and Embedded inside.

Example:

@DatabaseView("SELECT id, last_name FROM User")
  public class UserSummary {
      public long id;
      @ColumnInfo(name = "last_name")
      public String lastName;
  }
  

Views have to be registered to a RoomDatabase via Database#views. Room will automatically create a backing SQLite view.

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 POJOs when it is used in Dao. You can SELECT from DatabaseView like Entity, but you can not INSERT, DELETE or UPDATE DatabaseView. You can use ColumnInfo and Embedded inside.

Example:

@DatabaseView("SELECT id, last_name FROM User")
  public class UserSummary {
      public long id;
      @ColumnInfo(name = "last_name")
      public String lastName;
  }
  

Views have to be registered to a RoomDatabase via Database#views. Room will automatically create a backing SQLite view.

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.