Can local .db files be opened with Expo-Sqlite?

1.4k views Asked by At

I'm building a react native application on mobile (IOS and Android) with Expo and already have a .db file created from SQLite in which to make transactions with.

I've seen examples of projects which call a remote database from an API call as well as create a database if it does not exist already, but it's not clear if this can open a local database file in my project. So far providing a filepath for the .db file is not able to be found.

import * as SQLite from 'expo-sqlite';

const path = './SQLite/TFData.db';

const db = SQLite.openDatabase(path);

If this is not an error on my part, I would like to know what can be done to read an existing database file that is already located in my project if expo-sqlite is not able to do this.

1

There are 1 answers

1
quaz77 On

You only need to pass in the file's name. If TFData.db does not exist, it will be created.

import * as SQLite from 'expo-sqlite';

const name = 'TFData.db';

const db = SQLite.openDatabase(name);