1

Which one is the best local database for react native apps? And what does facebook and instagram use to store data locally?

safina
  • 212
  • 2
  • 13

1 Answers1

1

It's a nice question, but I don't know! but

I'm pretty sure that they use multiple NO-SQL DataBase for their server.

Anyway, If you are searching a local database for react-native

I will suggest you to use Realm -> https://realm.io/

It's use his own ORM and is build in Native for both platform IOS and Android, easy to use!

There some example: realm.js

import * as RealmDB from 'realm';

class Passenger extends RealmDB.Object {}
Passenger.schema = {
name: 'Passenger',
primaryKey: 'id',
properties: {
  'id'                : 'string',
  'firstname'         : { type: 'string', optional: true },
  'lastname'          : { type: 'string', optional: true },
  'birthdate'         : { type: 'int',    optional: true },
  'email'             : { type: 'string', optional: true },
  'phone'             : { type: 'string', optional: true },
  'child'             : { type: 'linkingObjects', objectType: 'Child', property: 'passengers' }
}
};


class Travel extends RealmDB.Object {}
Travel.schema = {
name: 'Child',
primaryKey: 'id',
properties: {
  'id'     : 'string',
  'name'                : 'string'
}
};


const realmInstance = new RealmDB({
schema: [Passenger, Child],
});
export default realmInstance;

use.js

import realmInstance from "./realm";
export default class use {

 static writeToRealm(){
  realm.write(() => {

  let passenger = realm.create('Passenger', {
  'id'            : "..."
  'firstname'     : "...",
  'lastname'      : "...",
  "..."
  })
 }

 static readPassengers(){
  const passengers = realmInstance.objects('Passengers');
  return passengers
 }
}

Hope it's help :)

G Clovs
  • 2,442
  • 3
  • 19
  • 24
  • Do you have a proper project structure for realm to use with react native, since the documentation and the example project is quite vague it only provides simple code for one component. But I need for multiple. – safina Nov 06 '17 at 15:55
  • or if you can answer this https://stackoverflow.com/questions/47137254/react-native-realm-project-structure – safina Nov 06 '17 at 15:57
  • Hope I help you – G Clovs Nov 06 '17 at 16:19