0

I got a knowledge database, I built an app with it. What I want to do is import the lines from CSV file to realm database with Realm Browser, I just want to query no insert and update. All examples are about insert data line first and then query it out, but can I first to query? Still need to create schema and new Realm() ?

const Realm = require('realm');
......
render(){
  class Car {};
  Car.schema = {
    name: 'Honda',
    properties: {
      id: 'int',
      price: 'string'
    }
  }
  let realm = new Realm({schema: [Car]});
  let myCar = realm.ojects('Car');

  return(<View>)
}

I want to know everytime I fetch data lines in new component, I should follow these codes? Cant I just create realm class and the fetch? Thank you for helping new beginner~

  • Show us examples of the code you tried, where it failed, etc. – casraf Jul 23 '17 at 08:55
  • I added some codes, and I want to know since I have import data into realm database, and the database have tables and columns, can I just fetch the data lines with out create Car schema? thank you ~ – Andrew Zhang Jul 23 '17 at 09:13

1 Answers1

1

The answer is yes, you can insert data through Realm Browser and then only query them in your app, but you still need to setup the schema and have Realm data file created in your app first.

In this case, you still need to create and opening Realms by calling something like this: let realm = new Realm({schema: [Car, Person]}); at least once in your app. Then you can print out your Realm's filepath through Realm.defaultPath, and use your Realm Browser to open your Realm data file.

Also, you don't need to do the Realm setup every time in your component's render function. You can leverage the module system to keep your code organized. This StackOverflow thread can be helpful to you, and search around other react-native + Realm example to learn how other people setup their Realm.

dotcomXY
  • 1,586
  • 1
  • 15
  • 18
  • thanks for you reply~ On Mac and iOS app, we have Realm Browser, is there same tools on android that we can import data from CSV or other kind of files? – Andrew Zhang Jul 24 '17 at 01:45
  • @AndrewZhang, try look into this [thread](https://stackoverflow.com/questions/28478987/how-to-view-my-realm-file-in-the-realm-browser/28486297#28486297), I followed the one using Android device monitor. You can pull out the realm file to your file system, use your Realm Browser to open it, import CSV data to it and put it back to overwrite the Realm file on your emulator. Is working for me. – dotcomXY Jul 24 '17 at 02:34
  • @AndrewZhang Can you upvote and accept my answer then? – dotcomXY Jul 24 '17 at 03:33