user5115790
user5115790

Reputation: 61

how can I export the data from my sqlite3 database to some json or csv file

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

Answers (2)

user10444815
user10444815

Reputation:

You can use SQLite Porter plugin. Don't worry this is an ionic plugin.

Installation

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))

usage

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
        });

for more information please visit

https://ionicframework.com/docs/native/sqlite-porter/
https://github.com/dpa99c/cordova-sqlite-porter#exportdbtojson

Hope that helps.

Upvotes: 1

V13
V13

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

Related Questions