Samiron Barai
Samiron Barai

Reputation: 31

Ionic 3 sqlite export and import database

I have created an app with ionic 3. I have used sqlite for database. I want to export database to a folder (outside of my app) and want to see all my back up database file in a list. Then I will choose any backup file and import to my database with file chooser.

Please help me. Thanks in advance.

Upvotes: 1

Views: 947

Answers (1)

Pankaj Sati
Pankaj Sati

Reputation: 2529

You can simply create a text file and store JSON encoded data inside it and later decode the data to store it back in the database.

Use Ionic Native File plugin for reading, creating and writing a file: https://ionicframework.com/docs/native/file/

  1. Create an empty directory in external storage.
  2. For taking a backup, Create a new text file and write your database table schema and rows in JSON format.
  3. To list previous backups, request native file plugin to return all files inside your previously created folder.
  4. To import a backup, first export current instance of database( Just for saving latest data). Then you can decode the JSON data inside your backup file and make insert queries for each row.

Upvotes: 2

Related Questions