how to create database in sqlite3 in react native

2.8k Views Asked by At

I went through all the details here in this link https://github.com/andpor/react-native-sqlite-storage. And I got confused with their documentation.

 ...
  1.SQLite.openDatabase({name : "testDB", createFromLocation : 1}, okCallback,errorCallback);
  // default - if your folder is called www and data file is named the same as the dbName - testDB in this example
  2.SQLite.openDatabase({name : "testDB", createFromLocation : "~data/mydbfile.sqlite"}, okCallback,errorCallback);
  // if your folder is called data rather than www or your filename does not match the name of the db
  3.SQLite.openDatabase({name : "testDB", createFromLocation : "/data/mydbfile.sqlite"}, okCallback,errorCallback);
  // if your folder is not in app bundle but in app sandbox i.e. downloaded from some remote location.
  ...

what the above statements will do ?
will it create a database or will it open a database which is there inside www or asset folder ?
can I create the database in whichever folder I want ?

No where i found a clear answer on this. That's why i'm asking this in stackoverflow.

1

There are 1 best solutions below

6
Bhupesh Kumar On

I also faced the same problem sometimes ago. You need to do all the setup according to the documentation. After that if you provide the location of the database.db using createFromLocation then you have to create a empty database file and paste it manually in assets and if you don't want to create manually then you can simply use SQLite.openDatabase({name : "testDB"}) it will create itself a database as the name provided. Hope this will help you, please tell me if it works.