i need to open prepopulated, encrypted database using react-native-sqlite-storage (modified by dryganet: https://github.com/dryganets/react-native-sqlite-storage/tree/sergeyd/sqlite-cipher), this prepopulated datatabase is downloaded from remote location using react-native-fs.
At this moment when i put database in assets folder (this database is copied during react-native run-android command) and fire method "openDatabase":
const dbName = "myDatabase.db";
const dbLocation = "~database.db";
const encryptionLey = "asdfghasdfgh";
const queryDatabase = async (tx) => {
const [sqliteTx, results] = await tx.executeSql(sqlQuery);
resultData = results;
};
const db = await SQLite.openDatabase({
name: dbName,
createFromLocation: dbLocation,
key: encryptionKey
}, (result) => {...}, (result) => {...});
await db.transaction(queryDatabase);
retrun resultData;
everything works correctly, but i need to download this database during runtime, so... when i change dbLocation to:
const dbLocation = fs.DocumentDirectoryPath + "/database.db";
and download sqlite database from remote location:
fs.downloadFile({,
fromUrl: "http://10.0.2.2:63074/Database/GetDatabase",
toFile: dbLocation,
}).promise.then(res => {
fs.exists(dbLocation).then(fileExist => {
...
});
});
Everything stops working, no errors occures, in debug console i can see this:
OPEN database: myDatabase.db
new transaction is waiting for open operation
Where is the problem? I uses SQLCipher to encrypt and decrypt database. Maybe there is another way to achieve this, the solution must works both on Android and iOS?