DatabaseView

@Target(allowedTargets = [AnnotationTarget.CLASS])
@Retention(value = AnnotationRetention.BINARY)
public annotation 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(@NonNull String value, @NonNull String viewName)

Public methods

final @NonNull String

The SELECT query.

final @NonNull String

The view name in the SQLite database.

Public constructors

DatabaseView

public DatabaseView(@NonNull String value, @NonNull String viewName)

Public methods

getValue

public final @NonNull String getValue()

The SELECT query.

Returns
@NonNull String

The SELECT query.

getViewName

public final @NonNull String getViewName()

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

Returns
@NonNull String

The SQLite view name.