1. Overview

This document explains how to integrate React native with SQLite DB.

2. Technologies and Tools Used

The following technologies and tools have been used to create a sample react application and integrating with it SQLite.

Technologies:

  • React Native
  • JavaScript
  • Node JS
  • SQLite

Tools:

  • Visual Studio Code
  • Android Studio

3. Use Case

Assume that there is a requirement to maintain user data within the mobile application.

4. Architecture 

After completing react native environment setup please follow the below steps.

  1. To create a sample project in react native, Execute the command in cmd prompt or visual studio terminal – npx react-native init <project name>
  2. Now the project will be created. To run the project first get into your project folder and execute the command – npx react-native run-android
  3. It will open in the virtual device and you can check it.
  4. To install SQLite – npm install react-native-sqlite-storage –save
  5. To import SQLite in your programimport { openDatabase } from ‘react-native-sqlite-storage’;
  6. To open DatabaseopenDatabase({ name: ‘user_db.db’, createFromLocation : 1})
  7. To make some database call you can use db variable to execute the below database query

db.transaction(function(txn)

{

txn.executeSql( query, //Query to execute as prepared statement argsToBePassed[], //Argument to pass for the prepared statement function(tx, res) {} //Callback function to handle the result response ); });

 

Project Code – reactsqlite

 

Home Screen

 

View All User

 

View User

Update User

Register User

User deleted Successfully

User Updated Successfully

Hope this document helps how to integrate React native with SQLite DB!!!

Recent Posts

Start typing and press Enter to search