react-nativereact-native-sqlite-storage

how to connect a pre-populated sqlite db in react-native-sqlite-storage?


I'm trying to connect an sqlite db using react-native-sqlite-storage, I followed the steps in github, it works fine on android but not on IOS, It looks like that it can not find the db file even I put it in the supposed folder "iOS/www", here is the open statement:

import {openDatabase} from 'react-native-sqlite-storage';
.....
const database = openDatabase({
      name: 'hebron_db.db',
      createFromLocation: '~hebron_db.db',
      location: 'default'
}, () => {
   console.log('db connection success')
}, () => {
   console.log('db connection error')
});

It always types "db connection success" even if I change the file name to be incorrect.

I use react native 0.62.2 Xcode: 11.5 npm: 6.13.4 macOS: Catalina 10.15.5

shouldn't it go to catch section if the file does not exist? any help please??


Solution

  • Here is the connection string that works finally:

    import {openDatabase} from 'react-native-sqlite-storage';
    const database = openDatabase({name : "hebron_db", createFromLocation : 1}, null, null);
    export default database;
    

    may it help others.