未添加获取适配器,请使用RxDB.plugin(需要('pouchdb-adapter-[适配器名称]');在ReactNative中

3bygqnnd  于 2023-01-27  发布在  React
关注(0)|答案(1)|浏览(132)
RxError: RxError:
RxDatabase.create(): Adapter not added. Use RxDB.plugin(require('pouchdb-adapter-[adaptername]');
Given parameters: {
adapter:"asyncstorage"}

database.js//我的代码

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;
}

我该怎么补救呢?

kokeuurv

kokeuurv1#

createDatabase函数在文档中是这样使用的。

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()
});

顺便说一下,RXDB文档中不赞成使用PouchDB。
RxStorage PouchDB的用法如下。

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
             */
        }
    )
});

相关问题