Backup #555
Replies: 2 comments 1 reply
-
I am also very interested in this. Right now, I am generating an export file with exportToJson. But I have problems importing it with the importFromJson method, since it does nothing and does not return any type of feedback in the catch. Greetings and excellent work with this plugin EDIT: I have discovered where I was making the mistake. I was reusing the connection to call the importFromJson method, instead of calling them from CapacitorSQLite. But with exportToJson if I should use the connection 🤔: Before import { CapacitorSQLite, SQLiteConnection } from "@capacitor-community/sqlite"
//...
const sqlite = new SQLiteConnection(CapacitorSQLite)
this.database = await sqlite.createConnection(VITE_SQLITE_DATABASE_NAME, false, "secret", 1, false)
//...
this.database.exportToJson("full") // <------ Work
//...
const isValid = await this.database.isJsonValid({ jsonstring: stringJson }) // <------ Don't work
if (isValid.result) {
await this.database
.importFromJson({ jsonstring: stringJson }) // <------ Don't work
} Now import { CapacitorSQLite, SQLiteConnection } from "@capacitor-community/sqlite"
//...
const sqlite = new SQLiteConnection(CapacitorSQLite)
this.database = await sqlite.createConnection(VITE_SQLITE_DATABASE_NAME, false, "secret", 1, false)
//...
this.database.exportToJson("full") // <------ Work
//...
const isValid = await CapacitorSQLite.isJsonValid({ jsonstring: stringJson }) // <------ Work
if (isValid.result) {
await CapacitorSQLite
.importFromJson({ jsonstring: stringJson }) // <------ Work
} |
Beta Was this translation helpful? Give feedback.
-
@BrunoRafaSilva the code must be import { CapacitorSQLite, SQLiteConnection } from "@capacitor-community/sqlite"
//...
const sqlite = new SQLiteConnection(CapacitorSQLite)
// Create a connection to the database
this.database = await sqlite.createConnection(VITE_SQLITE_DATABASE_NAME, false, "secret", 1, false)
// Open the database
await this.database.open();
//...
let jsonObj = await this.database.exportToJson("full") // <------ Work
//...
const isValid = await sqlite.isJsonValid(JSON.stringify(jsonObj.export));
if (isValid.result) {
// close the connection
await sqlite.closeConnection(VITE_SQLITE_DATABASE_NAME);
// import
result = await sqlite.importFromJson(JSON.stringify(jsonObj.export));
} Now if you want to use the database, you must create a connection and open the database and do any queries @BrunoRafaSilva Well in your app you can use the @capacitor/filesystem to backup the database in an internal or external storage, in using the @capacitor-community/sqlite plugin only the exportToJson and importFromJson is available. |
Beta Was this translation helpful? Give feedback.
-
Have a way to generate a backup file on Android and restore after New instalation?
Beta Was this translation helpful? Give feedback.
All reactions