PouchDB Adapters
When you use PouchDB RxStorage
, there are many adapters that define where the data has to be stored.
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.
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
Memory
In any environment, you can use the memory-adapter. It stores the data in the javascript runtime memory. This means it is not persistent and the data is lost when the process terminates.
Use this adapter when:
- You want to have really good performance
- You do not want persistent state, for example in your test suite
import {
createRxDatabase
} from 'rxdb'
import {
getRxStoragePouch
} from 'rxdb/plugins/pouchdb';
// npm install pouchdb-adapter-memory --save
addPouchPlugin(require('pouchdb-adapter-memory'));
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch('memory')
});
Memdown
With RxDB you can also use adapters that implement abstract-leveldown like the memdown-adapter.
// npm install memdown --save
// npm install pouchdb-adapter-leveldb --save
addPouchPlugin(require('pouchdb-adapter-leveldb')); // leveldown adapters need the leveldb plugin to work
const memdown = require('memdown');
const database = await createRxDatabase({
name: 'mydatabase',
storage: getRxStoragePouch(memdown) // the full leveldown-module
});
Browser
IndexedDB
The IndexedDB adapter stores the data inside of IndexedDB use this in browsers environments as default.
// 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.
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')
});