Navigate back to the homepage

how to delete SQLite database in android react native

Infinitbility
React Native
November 25th, 2020 · 1 min read

Hello Friends,

Welcome To Infinitbility!

React native SQLite & React native SQLite storage provide an option (SQLite.deleteDatabase) to delete db file from user phone but if you call SQLite.openDatabase for deleted db then db file re-creates on user phone.

if you want to completely remove the database then you have to delete the database from your project before the build.

SQLite.deleteDatabase use for deleting previous used database from users mobile.

before deleting the database check the user phone database file available or not.

Here I’m using a physical device for testing

SQLite database file location in android

here, I’m using rn-fetch-blob for check database file.

1import RNFetchBlob from 'rn-fetch-blob';
2
3const dirs = RNFetchBlob.fs.dirs;
4
5// for internal storage
6console.log(dirs.MainBundleDir + '/databases');
7
8// for external storage
9console.log(dirs.SDCardApplicationDir + '/databases');
10
11// show database list
12RNFetchBlob.fs.ls(dirs.MainBundleDir + '/databases').then((files) => {
13 console.log(files)
14});

for show database files

1RNFetchBlob.fs.ls(dirs.MainBundleDir + '/databases').then((files) => {
2 console.log(files)
3});

if you got your SQLite database file name then go to the second step to delete the database

Delete SQLite database file

For deleting the database use the below gist

1SQLite.deleteDatabase(
2 {name: 'test.db', location: '~www/test.db'},
3 () => { console.log('second db deleted'); },
4 error => {
5 console.log("ERROR: " + error);
6 }
7);

re-check database file available or not database folder.

Note

SQLite.deleteDatabase deleting only DB file from user phone.

Thanks for reading…

More From React Native Tutorial

Basics

1. Introduction To React Native

2. React Native Environment Setup using expo

3. React Native Environment Setup for windows

4. React Native Environment setup on Mac OS

5. React Native Environment setup on linux

6. React Native Project Structure

7. React Native State

8. React Native Props

9. React Native Styling

10. React Native Flexbox

11. React Native Text

12. React Native Textinput

13. React Native Commands

14. React Native ScrollView

Advances

1. React Native Dark Mode

2. React Native Fonts

3. React Native SQLite

4. React Native DatepickerAndroid

5. React native ScrollView scroll to position

6. How to align icon with text in react native

7. React Native Image

8. React Native Firebase Crashlytics

9. React Native Async Storage

10. React Native Share

Error & Issue Solution

1. Task :app:transformDexArchiveWithDexMergerForDebug FAILED In React Native

2. Expiring Daemon because JVM heap space is exhausted In React Native

3. Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED In React Native

4. Unable to determine the current character, it is not a string, number, array, or object in react native

5. App crashed immediately after install react native video or track player

6. how to delete SQLite database in android react native

7. React native material dropdown twice click issue

8. How to get the current route in react-navigation?

9. how to disable drawer on the drawer navigation screen?

10. Image not showing in ios 14 react native

11. React Native image picker launchimagelibrary on second time issue

12. how to open any link from react native render Html

13. Network request failed in react native fetch

14. React Native upload video example

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

React Native Image

How to add an image to react native, statically, dynamically, and data base64.

November 8th, 2020 · 1 min read

how to add datePickerAndroid in react native with color changes?

the simplest way to add datePickerAndroid in react native with color changes.

October 30th, 2020 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]