RxError: RxError:
RxDatabase.create(): Adapter not added. Use RxDB.plugin(require('pouchdb-adapter-[adaptername]');
Given parameters: {
adapter:"asyncstorage"}
database.js
//mycode
import RxDB from 'rxdb';
import schema from './ramsSchema';
RxDB.plugin(require('pouchdb-adapter-asyncstorage').default);
RxDB.plugin(require('pouchdb-adapter-http'));
const syncURL = 'couchDB url'
//this function initializes the RxDB if DB already exists else creates a new one and returns the db instance
export async function initializeDB(dbName,password) {
const db = await RxDB.create({
name: dbName.toLowerCase(),
adapter: 'asyncstorage',
password:'rams@1234',
multiInstance: false,
ignoreDuplicate: true,
});
const collection = await db.collection({
name:'rams',
schema,
});
collection.sync({
remote: syncURL + dbName.toLowerCase() + '/',
options: {
live: true,
retry: true,
},
});
return db;
}
How can I fix this?
The createDatabase function is used like this in the documentation.
import {
createRxDatabase
} from 'rxdb';
import { getRxStorageDexie } from 'rxdb/plugins/dexie';
// create a database
const db = await createRxDatabase({
name: 'heroesdb', // the name of the database
storage: getRxStorageDexie()
});
By the way, PouchDB is deprecated in the RXDB document.
RxStorage PouchDB Usage like this.
import { createRxDatabase } from 'rxdb';
import { getRxStoragePouch, addPouchPlugin } from 'rxdb/plugins/pouchdb';
addPouchPlugin(require('pouchdb-adapter-idb'));
const db = await createRxDatabase({
name: 'exampledb',
storage: getRxStoragePouch(
'idb',
{
/**
* other pouchdb specific options
* @link https://pouchdb.com/api.html#create_database
*/
}
)
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.