1
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?

1 Answer 1

-1

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
             */
        }
    )
});
1
  • This is not related to my question. I am using asyncstorage adapter to save and retrieve data from CouchDB.
    – Ramesh R
    Commented Jan 24, 2023 at 13:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.