Where does Expo store its SQLite databases?

I’m developing a small app, and would like to view and edit the contents of the SQLite database generated by it, to speed up development. I am creating it with the following command:

db = Expo.SQLite.openDatabase('dbname');

Where is it?

2 Likes

Relatedly; how do I drop the database easily to start again?

1 Like

What do you mean by “where is it”? The resulting “db” variable can be used to access the database now.

The database file. Like I said, I want to view and edit the contents of it, such as with http://sqlitebrowser.org/

1 Like

https://github.com/expo/expo/blob/d3e0190f900de5a688561d458b38ad592675b760/ios/Exponent/Versioned/Modules/Api/EXSQLite.m#L38-L40 is how the path is generated on iOS.

https://github.com/expo/expo/blob/d3e0190f900de5a688561d458b38ad592675b760/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/SQLiteModule.java#L173-L175 is how it’s generated on Android.

Expo.FileSystem.getInfoAsync('SQLite/<dbfilename>') will return a an object in which the uri property will have the file:// URI of the database file in your device / emulator / simulator.

Let me know if you need more clarification on this. :slight_smile:

2 Likes

https://github.com/expo/test-suite/blob/29e6e7692e365bc5430f693e1c13fd4ce37348d3/Tests/SQLite.js#L58-L65 shows how to get the file:// URI to the database file. If you are on iOS simulator on macOS, the path with the file:// prefix cut off should give you an absolute path to the file on macOS.

Expo is getting a proper FileSystem API soon that should address this in a proper way.

I’m still trying to find the database. I’m using Expo on a Mac Air, and the project is simply on my desktop. Unless I’m missing something, the database should reside in my project folder. In any event, I’m still unclear how to find the folder with the database file…has anybody found a way I could find this the terminal?

Amweiss, the database will reside on your device, not your desktop.

Nikki, thanks; I’ll try that today.

Thanks asday…makes sense…above it says “If you are on iOS simulator on macOS” you can find the path, etc, and I’m using the IOS simulator on a mac, but not sure where you look for that path…anybody know this? Thanks.

In case other people need this, if you are on a mac using an IOS simulator you can find the database by opening terminal and adding these two lines:

cd Library/Developer/CoreSimulator/Devices

find $PWD -name “[your database name]” -print

5 Likes

On Android, it’s under:
/data/data/host.exp.exponent/files/ExperienceData/YOURAPPNAME/SQLite/YOURDB

This worked for me

const { uri } = await FileSystem.getInfoAsync(
    `${documentDirectory}SQLite/${mainDatabaseName}`
)

i am use the “sdkVersion”: “36.0.0”, and i cant find this path when i connect the device to the computer .
i have data inside my db but i cant see it.
i print the path of it :
"file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540roei133%252FDogmimApp/SQLite/places.db "
but after i connect my device to the computer i try to go thh path but no path like that .
i run the app with the qr code of expo and it run on my device .
i will be happy if u let me know what is the problem in my case .

You cant access this location through the phone file browser or through Android studio unless you have a rooted phone. This is because the Expo App you install through the Play Store to scan the QR code is not in debug mode, therefore does not allow browsing the internal application files. One rather complex way of getting around this is de-compiling the Expo App and changing it to debug mode and resigning it, or use a rooted phone.

i have same problems in expo-sqlite .
i am using the current version of expo and node.js
i am using expo-sqlite .
first when i created a database file like
import * as SQLite from ‘expo-sqlite’;
const db=SQLite.openDatabase(“mydatabase.db”);
if created successfully and table will created and inserted successfully
like the code below:
useEffect(()=>{

try {

  db.transaction(trans=>{

    // trans.executeSql(

    //   'CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY AUTOINCREMENT, text TEXT, count INT)'

    // )

    trans.executeSql(

      'INSERT INTO items (text, count) values (?, ?)',["qadir",20],

    ()=>{console.log("Data Inserted");},

    ()=>{console.log("Data Not Inserted");}

    )

  },

  ()=>{

    console.log("Error while opening Database ");

  },

  ()=>{

    console.log("Database succeccfully created");

  }

  );

} catch (error) {

  console.log("My Error ",error);

}

},);
first time it’s work fine
but how can i find the database location in my laptop project folder?
can anyone give me the right answers?