https://developer.android.com/training/data-storage/room/accessing-data

@Dao
interface MyDao {
   @Insert(onConflict = OnConflictStrategy.REPLACE)
   fun insertUsers(vararg users: User)

   @Insert
   fun insertBothUsers(user1: User, user2: User)

   @Insert
   fun insertUsersAndFriends(user: User, friends: List<User>)
}

.

update

@Dao
interface MyDao {
   @Update
   fun updateUsers(vararg users: User)
}

.

delete

@Dao
interface MyDao {
   @Delete
   fun deleteUsers(vararg users: User)
}

.

query

@Dao
interface MyDao {
   @Query("SELECT * FROM user")
   fun loadAllUsers(): Array<User>
}
@Dao
interface MyDao {
   @Query("SELECT * FROM user WHERE age > :minAge")
   fun loadAllUsersOlderThan(minAge: Int): Array<User>
}
@Dao
interface MyDao {
   @Query("SELECT * FROM user WHERE age BETWEEN :minAge AND :maxAge")
   fun loadAllUsersBetweenAges(minAge: Int, maxAge: Int): Array<User>

   @Query("SELECT * FROM user WHERE first_name LIKE :search " +
          "OR last_name LIKE :search")
   fun findUserWithName(search: String): List<User>
}

.

더 많은 내용이 있는데 web page 참조

Comments are closed.

Post Navigation