Complete the code to define a Room entity with a primary key.
import androidx.room.Entity import androidx.room.PrimaryKey @Entity data class User( @PrimaryKey val [1]: Int, val name: String )
The primary key field is commonly named id to uniquely identify each entity instance.
Complete the DAO interface method to get all users from the database.
import androidx.room.Dao import androidx.room.Query @Dao interface UserDao { @Query("SELECT * FROM User") fun [1](): List<User> }
The method name getAllUsers clearly describes the action of retrieving all user records.
Fix the error in the database class declaration by completing the annotation.
import androidx.room.Database import androidx.room.RoomDatabase @Database(entities = [User::class], version = [1]) abstract class AppDatabase : RoomDatabase() { abstract fun userDao(): UserDao }
The database version must be a positive integer starting at 1 to manage schema versions properly.
Fill both blanks to define a DAO method that inserts a user and returns the new row ID.
import androidx.room.Dao import androidx.room.Insert @Dao interface UserDao { @Insert fun [1](user: User): [2] }
The method name insertUser clearly states the action, and the return type Long represents the new row ID.
Fill all three blanks to define a Room database class with entities, version, and an abstract DAO method.
import androidx.room.Database import androidx.room.RoomDatabase @Database(entities = [[1]::class], version = [2]) abstract class [3] : RoomDatabase() { abstract fun userDao(): UserDao }
The entity is User, the version is 1, and the database class is named AppDatabase.