React Native Installing Realm Mobile Database in iOS Android Tutorial

The Realm mobile database specially build for React Native applications is launched on Feb 2016 and since its been upgraded to version 2.2.0 at current date of March 2, 2018 . Realm supports object persistence and full query capabilities, It is faster then SQLite and used by most of  Android and iOS react native applications. React native supports all the mobile device platforms and runs directly inside Mobile phones, Tablets and Wearable devices.

What is Realm(How it Works) :

Realm is not an object relational mapping system and not build on above SQLite system, Realm usages native JavaScript objects dynamically mapped to a mobile database system syntax and usages Object relational modal. We can use Realm easily by installing its Library on our project. Realm is very easy to understand and faster than SQLite and Cross Platform mobile database. You can learn more about Realm on its official website here.

Contents in this project Installing Realm Mobile Database in iOS Android Tutorial React Native App :

1. Open your React Native project’s folder in Command Prompt / Terminal and execute below NPM command.

Screenshot :

Installing Realm Mobile Database

2. After successfully installed the Realm library your CMD screen should look like this.

3. Now we need to execute link command in order to refresh the complete React Native project and index the Realm mobile database.

Screenshot after executing link command:

Here you go guys now Realm Mobile database is successfully installed and ready to use in your react native project. Next step is start coding 🙂 .

4. Open your project’s App.js file and import StyleSheet, View, Image, Text and Platform component in your project.

5. Import Realm module in your project.

6. Create a Global scope variable named as realm, we would use this variable to opening and closing database.

7. Create constructor() in your project, Now we would execute the Schema command to make object Table in Realm.

name : Object Table Name .

Properties : Name of each field with its datatype.

If you want to know more about data types in Realm read its official documentation here.

8. Create Realm’s inbuilt write mode to insert data into Object table in render’s block.

9. Now we need to store all the object of User_Demo table into A. We need to apply JSON stringify method to popup all the items from object.

10. Create a Root View in render’s return block and Inside it Print all the Object using Text component.

11. Creating Style.

12. Complete source code for App.js File :

Screenshot :

4 Comments

  1. Hi, have you ever try to write native code in react native app using RealmSwift ?

  2. Hello;

    How can we press the information in the flatlist. ? I’m trying, but it’s not. ?

    render() {

    var A = realm.objects(‘User_Demo’);

    this.state.todoLists = JSON.stringify(A);

    realm.close();

    return (

    (

    {“Student Name : “+item.last_name}

    )}
    keyExtractor={(item) => item.id}

    />

    );
    }
    }

    Undefined error show…

Leave a Reply

Your email address will not be published. Required fields are marked *