You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will create a SQLite database via native Cordova called mydb.db.
Note that you will need to do this within the deviceready Cordova event. If you are stuck trying to get this to work, then please refer to the pouchdb-adapter-cordova-sqlite-demo project which contains a fully working demo that you can try out yourself to see how it should work. The code it adds is simply:
<scriptsrc="js/pouchdb-6.1.2.js"></script><scriptsrc="js/pouchdb.cordova-sqlite-2.0.2.js"></script><script>document.addEventListener('deviceready',function(){vardb=newPouchDB('database.db',{adapter: 'cordova-sqlite'});db.post({}).then(function(res){returndb.get(res.id);}).then(function(doc){/* etc. */}).catch(console.log.bind(console));});</script>
Note also that if you don't install a "SQLite plugin," it will fall back to WebSQL. If you are unsure whether or not a SQLite Plugin is successfully installed, try:
alert('SQLite plugin is installed?: '+(!!window.sqlitePlugin));
The reason it falls back to WebSQL is that cordova-plugin-websql adds a global openDatabase instead of a global cordova.sqlitePlugin. This adapter prefers cordova.sqlitePlugin but falls back to openDatabase.
Configuration
You can also pass in any options that are valid for Cordova-sqlite-storage, such as location,
androidDatabaseImplementation, etc.:
If you want to use the legacy _pouch_mydb.db format (with the _pouch_ prefix), then do this:
varPouchAdapterCordovaSqlite=require('pouchdb-adapter-cordova-sqlite');cordovaSqlitePlugin.use_prefix=true;// use the legacy '_pouch' prefixPouchDB.plugin(PouchAdapterCordovaSqlite);vardb=newPouchDB('mydb.db',{adapter: 'cordova-sqlite'});
Historical note
Until PouchDB 6.0.0, PouchDB's regular websql adapter supported the Cordova SQLite Plugin automatically. However, the PouchDB team found this
to be confusing, error-prone, and difficult to configure, which is why it was extracted into a separate plugin. You can read details in PouchDB's list of breaking changes.
Changelog
2.0.0
Automatically registered the plugin if it detects window.PouchDB. This means for people using <script> tags, you no longer need to explicitly call PouchDB.plugin().
1.0.0
Initial release
About
PouchDB adapter for Cordova SQLite. Designed for PouchDB 6+.