Bulk Insert In Realm
I have decided to use Realm for my project. I've gone through the documentation and cannot understand how to get all my phone contacts imported into my Realm database. Has anyone d
Solution 1:
With Realm there is no need for something which is directly adequate to bulk inserts available in SQLite. There is no overhead of a query language involved.
You can just insert multiple objects via Realm#copyToRealm batched in a single write transaction. If you need to import JSON data, there is Realm#createOrUpdateAllFromJson(JSONArray).
Solution 2:
in 2016 realm added a new api for insert bulk data
realm.insertOrUpdate(Collections datas);
try this method and for more, look at here. https://realm.io/blog/realm-java-1-1-0/
Solution 3:
full code in kotlin
funinsertList(list: MutableList<MenuItems>) {
val realm = AppDatabase.getRealmInstance() //get Realm Instancetry {
realm.executeTransaction { realmTr ->
realmTr.copyToRealm(list)
}
} catch (error: Exception) {
error.printStackTrace()
} finally {
realm.close()
}
}
Post a Comment for "Bulk Insert In Realm"