Reputation: 61
I do not know much about it, but I'm currently using the sqlite3 plugin in ionic 3, and I'm storing forms that users use. I would like at a certain moment to export this data to some conventional format such as json or csv. is this possible? and how?
thank you very much.
Upvotes: 0
Views: 1870
Reputation:
You can use SQLite Porter plugin. Don't worry this is an ionic plugin.
Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add uk.co.workingedge.cordova.plugin.sqliteporter
$ npm install --save @ionic-native/sqlite-porter
and then add the plugin to your module.
and on exporting you're data from your database to for example json (exportDbToJson(db))
var db = window.openDatabase("Test", "1.0", "TestDB", 1 * 1024);
var successFn = function(json, count){
console.log("Exported JSON: "+json);
alert("Exported JSON contains equivalent of "+count+" SQL statements");
};
cordova.plugins.sqlitePorter.exportDbToJson(db, {
successFn: successFn
});
https://ionicframework.com/docs/native/sqlite-porter/
https://github.com/dpa99c/cordova-sqlite-porter#exportdbtojson
Hope that helps.
Upvotes: 1
Reputation: 1093
Try using the command line sqlite binary:
sqlite3 -csv /path/to/sqlite/file 'SELECT * FROM yourtable'
You can obviously construct whatever query you like.
Upvotes: 0