Stay organized with collections
Save and categorize content based on your preferences.
Version 2.1.0 and higher of the Room persistence
library provides support for SQLite database
views, allowing you
to encapsulate a query into a class. Room refers to these query-backed classes
as views, and they behave the same as simple data objects when used in a
DAO.
Create a view
To create a view, add the
@DatabaseView annotation to a class.
Set the annotation's value to the query that the class should represent.
The following code snippet provides an example of a view:
Kotlin
@DatabaseView("SELECT user.id, user.name, user.departmentId,"+"department.name AS departmentName FROM user "+"INNER JOIN department ON user.departmentId = department.id")dataclassUserDetail(valid:Long,valname:String?,valdepartmentId:Long,valdepartmentName:String?)
Java
@DatabaseView("SELECT user.id, user.name, user.departmentId,"+"department.name AS departmentName FROM user "+"INNER JOIN department ON user.departmentId = department.id")publicclassUserDetail{publiclongid;publicStringname;publiclongdepartmentId;publicStringdepartmentName;}
Associate a view with your database
To include this view as part of your app's database, include the
views property in your app's
@Database annotation:
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-01-03 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-01-03 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-01-03 UTC."]]