PouchDB Adapters
@@ -21,8 +21,7 @@ Depending on which environment you work in, you can choose between different adapters. For example, in the browser you want to store the data inside of IndexedDB but on NodeJS you want to store the data on the filesystem.This page is an overview over the different adapters with recommendations on what to use where.
-
IMPORTANT:
-The PouchDB RxStorage is removed from RxDB and can no longer be used in new projects. You should switch to a different RxStorage.
+The PouchDB RxStorage is removed from RxDB and can no longer be used in new projects. You should switch to a different RxStorage.
Please always ensure that your pouchdb adapter-version is the same as pouchdb-core
in the rxdb package.json. Otherwise, you might have strange problems.
Any environment
@@ -43,7 +42,7 @@IndexedDB// npm install pouchdb-adapter-idb --save
addPouchPlugin(require('pouchdb-adapter-idb'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('idb')
});
// npm install pouchdb-adapter-idb --save
addPouchPlugin(require('pouchdb-adapter-idb'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('idb')
});
IndexedDB
A reimplementation of the indexeddb adapter which uses native secondary indexes. Should have a much better performance but can behave different on some edge cases.
-Notice: Multiple users have reported problems with this adapter. It is not recommended to use this adapter.
+Multiple users have reported problems with this adapter. It is not recommended to use this adapter.
// npm install pouchdb-adapter-indexeddb --save
addPouchPlugin(require('pouchdb-adapter-indexeddb'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('indexeddb')
});
Websql
This adapter stores the data inside of websql. It has a different performance behavior. Websql is deprecated. You should not use the websql adapter unless you have a really good reason.
@@ -70,7 +69,7 @@react-na
import { createRxDatabase } from 'rxdb';
import { addPouchPlugin, getRxStoragePouch } from 'rxdb/plugins/pouchdb';
import SQLite from 'react-native-sqlite-2'
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'
const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
addPouchPlugin(SQLiteAdapter);
addPouchPlugin(require('pouchdb-adapter-http'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('react-native-sqlite') // the name of your adapter
});
asyncstorage
import { createRxDatabase } from 'rxdb';
import { addPouchPlugin, getRxStoragePouch } from 'rxdb/plugins/pouchdb';
import SQLite from 'react-native-sqlite-2'
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite'
const SQLiteAdapter = SQLiteAdapterFactory(SQLite)
addPouchPlugin(SQLiteAdapter);
addPouchPlugin(require('pouchdb-adapter-http'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('react-native-sqlite') // the name of your adapter
});
Uses react-native's asyncstorage.
-Notice: There are known problems with this adapter and it is not recommended to use it.
+There are known problems with this adapter and it is not recommended to use it.
// npm install pouchdb-adapter-asyncstorage --save
addPouchPlugin(require('pouchdb-adapter-asyncstorage'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('node-asyncstorage') // the name of your adapter
});
asyncstorage-down
A leveldown adapter that stores on asyncstorage.
@@ -78,6 +77,6 @@asyncstora
Cordova / Phonegap / Capacitor
cordova-sqlite
Uses cordova's global cordova.sqlitePlugin
. It can be used with cordova and capacitor.
// npm install pouchdb-adapter-cordova-sqlite --save
addPouchPlugin(require('pouchdb-adapter-cordova-sqlite'));
/**
* In capacitor/cordova you have to wait until all plugins are loaded and 'window.sqlitePlugin'
* can be accessed.
* This function waits until document deviceready is called which ensures that everything is loaded.
* @link https://cordova.apache.org/docs/de/latest/cordova/events/events.deviceready.html
*/
export function awaitCapacitorDeviceReady(): Promise<void> {
return new Promise(res => {
document.addEventListener('deviceready', () => {
res();
});
});
}
async function getDatabase(){
// first wait until the deviceready event is fired
await awaitCapacitorDeviceReady();
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch(
'cordova-sqlite',
// pouch settings are passed as second parameter
{
// for ios devices, the cordova-sqlite adapter needs to know where to save the data.
iosDatabaseLocation: 'Library'
}
)
});
}