我决定在我的项目中使用 Realm。我已经阅读了文档,但无法理解如何将我所有的电话联系人导入到我的 Realm 数据库中。 以前有人做过这种项目吗?请帮忙。
我使用了具有批量插入选项的 Sugar ORM。 Realm 是否具有相同的功能或是否有替代方案?
这是我到目前为止所做的:
package com.advisualinc.switchchat.Realm_DB;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
/**
* Created by Veeresh on 10/19/2015.
*/
public class R_ContactDB extends RealmObject {
private String name;
@PrimaryKey
private String phone;
private boolean matchedWithRecent;
private int status;
public R_ContactDB(String name, String phone, boolean matchedWithRecent, int status)
{
this.name = name;
this.phone = phone;
this.matchedWithRecent = matchedWithRecent;
this.status = status;
}
public R_ContactDB()
{
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public boolean isMatchedWithRecent() {
return matchedWithRecent;
}
public void setMatchedWithRecent(boolean matchedWithRecent) {
this.matchedWithRecent = matchedWithRecent;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
最佳答案
有了 Realm,就不需要直接满足 SQLite 中可用的批量插入的东西。不涉及查询语言的开销。
您可以通过 Realm#copyToRealm 插入多个对象在单个写入事务中批处理。 如果需要导入JSON数据,有Realm#createOrUpdateAllFromJson(JSONArray) .
关于android - 在 Realm 中批量插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33229006/