# DatabaseView

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

*** ** * ** ***

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 data object when it is used in a `https://developer.android.com/reference/kotlin/androidx/room3/Dao`. You can SELECT FROM a `https://developer.android.com/reference/kotlin/androidx/room3/DatabaseView` similar to an `https://developer.android.com/reference/kotlin/androidx/room3/Entity`, but you can not `INSERT`, `DELETE` or `UPDATE` into a `https://developer.android.com/reference/kotlin/androidx/room3/DatabaseView`.

Similar to an `https://developer.android.com/reference/kotlin/androidx/room3/Entity`, you can use `https://developer.android.com/reference/kotlin/androidx/room3/ColumnInfo` and `https://developer.android.com/reference/kotlin/androidx/room3/Embedded` 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 Room database via `https://developer.android.com/reference/kotlin/androidx/room3/Database#views()`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/Dao` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/Database` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/ColumnInfo` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/Embedded` |   |

## Summary

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

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

## Public constructors

### DatabaseView

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

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

## Public properties

### value

Cmn

```
val value: String
```

The SELECT query.

| Returns |
|---|---|
| `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 |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The SQLite view name. |