카테고리 없음
Realm kotlin Delete
hik14
2022. 7. 26. 13:52
1. realm.write() 또는 realm.writeBlocking()을 사용하여 write 트랜잭션 생성.
2. realm.query()를 사용하여 삭제하려는 객체에 대한 트랜잭션의 mutableRealm 을 쿼리합니다.
객체 유형을 query()에 전달된 Type params로 지정
쿼리를 지정하여 반환된 객체 집합을 필터링.
쿼리가 올바른 개체를 반환하도록 하려면 기본 키 값과 같은 고유 식별 정보로 필터링
3. realmResults.delete()를 사용하여 쿼리에서 반환된 RealmResults 집합을 삭제합니다.
Delete an Object - Kotlin SDK
realm.write {
// fetch the frog by primary key value, passed in as argument number 0
val frog: Frog =
this.query<Frog>("_id == $0", PRIMARY_KEY_VALUE).find().first()
// call delete on the results of a query to delete the object permanently
delete(frog)
}
* write { ... } 트랜잭션 내의 realm에서만 객체를 삭제할 수 있습니다.
Delete Multiple Objects - Kotlin SDK
realm.write {
// fetch 7 frogs of the bullfrog species from the realm
val frogs: RealmResults<Frog> =
this.query<Frog>("species == 'bullfrog' LIMIT(7)").find()
// call delete on the results of a query to delete those objects permanently
delete(frogs)
}
Delete All Objects of a Type - Kotlin SDK
realm.write {
// fetch all frogs from the realm
val frogs: RealmResults<Frog> = this.query<Frog>().find()
// call delete on the results of a query to delete those objects permanently
delete(frogs)
}