Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 1.91 KB

rx-storage-indexeddb.md

File metadata and controls

67 lines (48 loc) · 1.91 KB

IndexedDB RxStorage

The IndexedDB RxStorage is based on plain IndexedDB and can be used in browsers, electron or hybrid apps.

Pros

  • It is really fast because it uses many performance optimizations for IndexedDB.
  • It has a small build size.
  • It allows to use boolean values as index.

Cons

  • It is part of the RxDB Premium plugin that must be purchased.
  • Only runs on runtimes that support IndexedDB v2, so it does not work on Internet Explorer.

Usage

import {
    createRxDatabase
} from 'rxdb';
import {
    getRxStorageIndexedDB
} from 'rxdb-premium/plugins/storage-indexeddb';

const db = await createRxDatabase({
    name: 'exampledb',
    storage: getRxStorageIndexedDB({
        /**
         * For better performance, queries run with a batched cursor.
         * You can change the batchSize to optimize the query time
         * for specific queries.
         * You should only change this value when you are also doing performance measurements.
         * [default=300]
         */
        batchSize: 300
    })
});

Overwrite/Polyfill the native IndexedDB

Node.js has no IndexedDB API. To still run the IndexedDB RxStorage in Node.js, for example to run unit tests, you have to polyfill it. You can do that by using the fake-indexeddb module and pass it to the getRxStorageDexie() function.

import { createRxDatabase } from 'rxdb';
import { getRxStorageIndexedDB } from 'rxdb-premium/plugins/storage-indexeddb';

//> npm install fake-indexeddb --save
const fakeIndexedDB = require('fake-indexeddb');
const fakeIDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange');

const db = await createRxDatabase({
    name: 'exampledb',
    storage: getRxStorageIndexedDB({
        indexedDB: fakeIndexedDB,
        IDBKeyRange: fakeIDBKeyRange
    })
});