Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

How do I use a prepopulated SQLite DB with Expo on Android?

$
0
0

I'm trying to use a prepopulated SQLite DB for my react native app. I'm using Expo and the downloadAsync() Function to load my DB from my assets folder. This works as expected on IOS, as I can load the DB and retrieve the data.

On Android however I just can't get this to work. The db file is there in the internal storage of my emulator, but every time I try to retrieve data, an error occurs since 'there is no such table'.

My guess is that SQLite doesn't properly search for my db but instead creates a new one, where my tables are obviously missing.

I've been trying for over 7 hours now, so I appreciate any kind of help.

Folder structure:

App.js-assets--db---db.db-src--connection---connectionClass

App.js

const App = () => {    const [dbLoaded, setDbLoaded] = useState(false);       if(!dbLoaded){        downloadDB().then((value) => setDbLoaded(value));        return <></>    } else {        return (<Navigation/>        );    }};

ConnectionClass.js

export const downloadDB = async () => {    await FileSystem.deleteAsync(`${FileSystem.documentDirectory}SQLite`, {idempotent : true});    await FileSystem.makeDirectoryAsync(`${FileSystem.documentDirectory}SQLite`, {intermediates: true });    return await FileSystem.downloadAsync(        Asset.fromModule(require('../../assets/db/WaKanji.db')).uri,        `${FileSystem.documentDirectory}SQLite/WaKanji.db`    ).then(({status}) => {        if(status === 200){                           return true        }        return false    }).catch(error => {        console.log('Err\n'+ error);        return false;    });};

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>