I am using the sqlite plugin in react native and want to upload the db in react native.
But I am getting stuck on how to get the path of the sqlite db
Any help?
I am using the sqlite plugin in react native and want to upload the db in react native.
But I am getting stuck on how to get the path of the sqlite db
Any help?
Here's how to use React-native sqlite:
npm install --save react-native-sqlite-storagecd ios && pod install && cd ... Linking is not required in React Native 0.60 and aboveindex.ios.js

errorCB(err) {
console.log("SQL Error: " + err);
},
successCB() {
console.log("SQL executed fine");
},
openCB() {
console.log("Database OPENED");
},
var db = SQLite.openDatabase("test.db", "1.0", "Test Database", 200000, openCB, errorCB);
db.transaction((tx) => {
tx.executeSql('SELECT * FROM Employees a, Departments b WHERE a.department = b.department_id', [], (tx, results) => {
console.log("Query completed");
// Get rows with Web SQL Database spec compliance.
var len = results.rows.length;
for (let i = 0; i < len; i++) {
let row = results.rows.item(i);
console.log(`Employee name: ${row.name}, Dept Name: ${row.deptName}`);
}
// Alternatively, you can use the non-standard raw method.
/*
let rows = results.rows.raw(); // shallow copy of rows Array
rows.map(row => console.log(`Employee name: ${row.name}, Dept Name: ${row.deptName}`));
*/
});
});
NOTE: You must create a DB file for SQLite that uses the .db extension to use with
React Native. so you can make it usingsqlitbrowser.
reference document:
Where as on Android the location of the database file is fixed, there are three choices of where the database file can be located on iOS. The 'location' parameter you provide to openDatabase call indicated where you would like the file to be created. This parameter is neglected on Android.
where the location option may be set to one of the following choices:
In Android studio When Launch succeeded: In Device File Explorer> data> data> com.nameofyourapp> databases
You can also click on the bottom tab of android studio 'Database inspector' to see the database changes in real time. :)