To store the data inside of IndexedDB in the browser, you can also use the Dexie.js RxStorage.
Dexie.js is a minimal wrapper around IndexedDB.
For the Dexie based RxStorage
, we use the mingo query handler.
- Can use Dexie.js addons.
- It does not support attachments
- It does not support boolean indexes
- Does not use a Batched Cursor or custom indexes which makes queries slower compared to the IndexedDB RxStorage.
import { createRxDatabase } from 'rxdb';
import { getRxStorageDexie } from 'rxdb/plugins/storage-dexie';
const db = await createRxDatabase({
name: 'exampledb',
storage: getRxStorageDexie()
});
Node.js has no IndexedDB API. To still run the Dexie 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 { getRxStorageDexie } from 'rxdb/plugins/storage-dexie';
//> npm install fake-indexeddb --save
const fakeIndexedDB = require('fake-indexeddb');
const fakeIDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange');
const db = await createRxDatabase({
name: 'exampledb',
storage: getRxStorageDexie({
indexedDB: fakeIndexedDB,
IDBKeyRange: fakeIDBKeyRange
})
});
Dexie.js has its own plugin system with many plugins for encryption, replication or other use cases. With the Dexie.js RxStorage
you can use the same plugins by passing them to the getRxStorageDexie()
function.
const db = await createRxDatabase({
name: 'exampledb',
storage: getRxStorageDexie({
addons: [ /* Your Dexie.js plugins */ ]
})
});
Dexie.js does not support boolean indexes because they are not a valid index key in IndexedDB itself. See w3c/IndexedDB#76. To index boolean fields, you can:
- Substitute the index field with a non boolean field. For example you can use a number field and store
0
asfalse
and1
astrue
, - or use the the IndexedDB RxStorage which supports boolean indexes because it does not use the IndexedDB indexes but custom index string instead.