Issue
I am trying to use cordova-plugin-sqlite-2 plugin in my Ionic app, but I'm not sure how to use its features for opening or creating a database . What import () statement should I give to use this plugin ?
I have referred this Question in which 'import { SQLite } from 'ionic-native'; is used , but it is showing error when used.
Solution
I'm not sure if you're trying to use sqlite only or some other DB, but I have recently used PouchDB inside my Ionic5+ReactJs+Typescript app, and here is what I did:
- Install the necessary packages
npm install pouchdb pouchdb-adapter-cordova-sqlite cordova-plugin-sqlite-2 @types/pouchdb @ionic-native/sqlite
Please note that @types packages are for typescript support.
- Create a sample database
import PouchDB from "pouchdb";
import "cordova-plugin-sqlite-2/dist/sqlite-plugin";
import cordovaSqlitePlugin from "pouchdb-adapter-cordova-sqlite";
PouchDB.plugin(cordovaSqlitePlugin);
let sampleDB = new PouchDB("sampleDatabase", { adapter: "cordova-sqlite", });
- After that you can use the database object directly
sampleDB.post({name: "my first object"});
Answered By - Ibrahim Awad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.