SQLite Porter
This Cordova/Phonegap plugin can be used to import/export to/from a SQLite database using either SQL or JSON.
https://github.com/dpa99c/cordova-sqlite-porter
Stuck on a Cordova issue?
If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.
Installation
- Capacitor
- Cordova
- Enterprise
$ npm install uk.co.workingedge.cordova.plugin.sqliteporter
$ npm install @awesome-cordova-plugins/sqlite-porter
$ ionic cap sync
$ ionic cordova plugin add uk.co.workingedge.cordova.plugin.sqliteporter
$ npm install @awesome-cordova-plugins/sqlite-porter
Ionic Enterprise comes with fully supported and maintained plugins from the Ionic Team. Learn More or if you're interested in an enterprise version of this plugin Contact Us
Supported Platforms
- Amazon Fire OS
- Android
- BlackBerry 10
- Browser
- iOS
- Tizen
- Windows
- Windows Phone
Usage
React
Learn more about using Ionic Native components in React
Angular
import { SQLitePorter } from '@awesome-cordova-plugins/sqlite-porter/ngx';
constructor(private sqlitePorter: SQLitePorter) { }
...
let db = window.openDatabase('Test', '1.0', 'TestDB', 1 * 1024);
// or we can use SQLite plugin
// we will assume that we injected SQLite into this component as sqlite
this.sqlite.create({
name: 'data.db',
location: 'default'
})
.then((db: any) => {
let dbInstance = db._objectInstance;
// we can pass db._objectInstance as the database option in all SQLitePorter methods
});
let sql = 'CREATE TABLE Artist ([Id] PRIMARY KEY, [Title]);' +
'INSERT INTO Artist(Id,Title) VALUES ("1","Fred");';
this.sqlitePorter.importSqlToDb(db, sql)
.then(() => console.log('Imported'))
.catch(e => console.error(e));