Let's create an interface named UserDAO.kt, and annotated with @DAO annotation. This will help Room to identify the DAO class. Here is the code for the DAO interface:
@Dao
interface UserDAO
In this interface, we will create functions that will be responsible for inserting, deleting, and getting the user details:
@Insert
fun addNewUser(users: Users)
In the preceding code, @Insert is used to insert a user:
@Query("DELETE FROM USERS")
fun deleteAllUsers()
In the previous code, @Query("DELETE FROM USERS") is used to delete all the users from the USERS table:
@Query("SELECT * FROM USERS")
fun getAllUsers(): List<Users>
In this code, @Query("SELECT * FROM USERS") is used to get all the users as a list from the USERS table.