Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing location property is not showing the DB #19

Open
devaarx opened this issue Sep 17, 2023 · 3 comments
Open

changing location property is not showing the DB #19

devaarx opened this issue Sep 17, 2023 · 3 comments

Comments

@devaarx
Copy link

devaarx commented Sep 17, 2023

I am trying to save the DB file inside the App Data folder (e.g. /storage/emulated/0/Android/data/com.package.name). And I have this code:

// other imports
import { QuickSQLiteConnection, open } from "react-native-quick-sqlite";

// get the app directory
const externalDirectory = RNFS.ExternalDirectoryPath; // --> /storage/emulated/0/Android/data/com.package.name/files location

// open the db
const db = open({ name: "default.db", location: externalDirectory });

This opens the DB fine, I am not able to see any file inside the above mentioned location. And, if I change the location property to any other directory (e.g. RNFS.DownloadDirectoryPath), this also not showing any DB, but if I revert to old location, I still have the older data.

My requirement is that I want to give an option to the user to export (backup) the local database, so that they can import it later, or onto any other devices. How can I achieve this?

Thank you in advance!

@devaarx devaarx changed the title location property is not working while opening DB using open changing location property is not showing the DB Sep 17, 2023
@xiaoxiaoboa
Copy link

I have the same problem: after modifying the location, I can't see the database file. Have you solved this problem?

@devaarx
Copy link
Author

devaarx commented Oct 19, 2023

I have the same problem: after modifying the location, I can't see the database file. Have you solved this problem?

For now I am doing a "hack" like this:

SQLite.openDatabase({ name: DB_NAME, location: "default" });

const dbFileLocation = RNFS.DocumentDirectoryPath.split(PACKAGE_NAME)[0] + PACKAGE_NAME;
const dbFilePath = dbFileLocation + "/databases/" + DB_NAME;

The RNFS.DocumentDirectoryPath will give the app data location + /files. So I split with my package name, and appending /databases/ + DB_NAME, so you will end up with your database file. You can copy it or do whatever you'd like. I am not sure if this will work in iOS.

@ospfranco
Copy link

ospfranco commented Nov 9, 2023

location only appends to the default path (NSDocumentsDirectory on iOS and the files dir on android).

It doesn't absolutely replace the path. If you want to navigate to the databases folder you can use a relative path:

SQLite.openDatabase({name: DB_NAME, location: '../databases'})

The problem is that doing it this way might break in future Android versions where the database path might change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants