Import Data to Realm Database

房东的猫 提交于 2019-12-06 14:23:27

问题


I want to use a centralized database and am looking at various options to do so. From my understanding, I have three main options: SQLite, Realm, and CoreData. Are these options fine for a large centralized database for all users.

Additionally, I am trying to import data from JSON and CSV into a Realm database. Does Realm have this functionality?


回答1:


As for now Realm does not seem to have the import functionality that you need. Check this thread for more information.

Realm does have a great documentation that you can read at Realm and for SQLite there is this framework (there are for sure more out there) and they both support Swift 2.x. You have to check what suits your requests most.

I can also recommend you to read this database thread at reddit.




回答2:


public String composeJsonFromRealm(){
        ArrayList<HashMap<String, String>> wordList;
        wordList = new ArrayList<HashMap<String, String>>();
       // Build the query looking at all users:
        // Execute the query:
        RealmResults<User> users = realm.where(User.class).findAll();

        if (users.size()>0){
                User user = users.first();
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("name", user.getName());
                map.put("email",user.getEmail());
                wordList.add(map);


        }

        Gson gson = new GsonBuilder().create();

        return gson.toJson(wordList);

    }



回答3:


I am trying to import data from JSON and CSV into a Realm database. Does Realm have this functionality?

With Realm Cocoa Converter you can import CSV, XLSX, and JSON, and export CSV data. Though, at the moment, it only supports OS X.




回答4:


As of now, Realm Studio does have the import functionality from CSV.

Open the Realm Studio, File -> Create Realm from -> CSV

Cheers,

Murat



来源:https://stackoverflow.com/questions/34362618/import-data-to-realm-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!