Where can I find the database for Expo-Sqlite? It's for my React Native activity

70 Views Asked by At

I am looking for the db file so that I can edit it with the db browser.

I tried looking for it but couldn't seem to find it. I heard that it's impossible to find with "expo-sqlite" instead of "react-native-sqlite-storage".

1

There are 1 best solutions below

4
Sally Azulay On

As for the expo-sqlite docs looks like you need to configure sqlite server on your machine using SQLite

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.

Once you'll do that you'll be able to access your db using the following script:

import * as FileSystem from 'expo-file-system';
import * as SQLite from 'expo-sqlite';
import { Asset } from 'expo-asset';

async function openDatabase(pathToDatabaseFile: string): Promise<SQLite.WebSQLDatabase> {
  if (!(await FileSystem.getInfoAsync(FileSystem.documentDirectory + 'SQLite')).exists) {
    await FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'SQLite');
  }
  await FileSystem.downloadAsync(
    Asset.fromModule(require(pathToDatabaseFile)).uri,
    FileSystem.documentDirectory + 'SQLite/myDatabaseName.db'
  );
  return SQLite.openDatabase('myDatabaseName.db');
}

Hope that helps.