# DatabaseView

# DatabaseView

Artifact:[androidx.room:room-common](https://developer.android.com/jetpack/androidx/releases/room)  
[View Source](https://cs.android.com/search?q=file:androidx/room/DatabaseView.kt+class:androidx.room.DatabaseView)  
Added in[2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/room/DatabaseView "View this page in Java")
Common/AllAndroid/JVMNative/C/iOSJavaScript
  - Cmn  

  ```
  @Target(allowedTargets = [AnnotationTarget.CLASS])
  @Retention(value = AnnotationRetention.BINARY)
  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](https://developer.android.com/reference/kotlin/androidx/room/Dao). You can SELECT FROM a[DatabaseView](https://developer.android.com/reference/kotlin/androidx/room/DatabaseView)similar to an[Entity](https://developer.android.com/reference/kotlin/androidx/room/Entity), but you can not INSERT, DELETE or UPDATE into a[DatabaseView](https://developer.android.com/reference/kotlin/androidx/room/DatabaseView).

Similar to an[Entity](https://developer.android.com/reference/kotlin/androidx/room/Entity), you can use[ColumnInfo](https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo)and[Embedded](https://developer.android.com/reference/kotlin/androidx/room/Embedded)inside to customize the data class.

Example:  

```kotlin
@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](https://developer.android.com/reference/kotlin/androidx/room/Database#views()).  

|                                       See also                                        |
|---------------------------------------------------------------------------------------|---|
| [Dao](https://developer.android.com/reference/kotlin/androidx/room/Dao)               |   |
| [Database](https://developer.android.com/reference/kotlin/androidx/room/Database)     |   |
| [ColumnInfo](https://developer.android.com/reference/kotlin/androidx/room/ColumnInfo) |   |
| [Embedded](https://developer.android.com/reference/kotlin/androidx/room/Embedded)     |   |

## Summary

|                                                                                                                                                     ### Public constructors                                                                                                                                                      |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [DatabaseView](https://developer.android.com/reference/kotlin/androidx/room/DatabaseView#DatabaseView(kotlin.String,kotlin.String))`(value: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, viewName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` | Cmn |

|                               ### Public properties                               |
|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|-----|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [value](https://developer.android.com/reference/kotlin/androidx/room/DatabaseView#value()) The SELECT query.                           | Cmn |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [viewName](https://developer.android.com/reference/kotlin/androidx/room/DatabaseView#viewName()) The view name in the SQLite database. | Cmn |

## Public constructors

### DatabaseView

Cmn  
Added in[2.8.4](https://developer.android.com/jetpack/androidx/releases/room#2.8.4)  

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

## Public properties

### value

Cmn  

```
val value: String
```

The SELECT query.  

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|-------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The SELECT query. |

### viewName

Cmn  

```
val viewName: String
```

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

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|-----------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | The SQLite view name. |