/redux-persist-nedb-storage

Storage adapter to use nedb with redux-persist

Primary LanguageJavaScript

redux-persist-nedb-storage

Built on top of the codebase from redux-persist-electron-storage

npm version npm downloads

Storage adapter to use nedb with redux-persist

Installation

npm

npm i -S nedb redux-persist-nedb-storage deep-parse-json

yarn

yarn add nedb redux-persist-nedb-storage deep-parse-json

Usage

To use redux-persist-nedb-storage, configure redux-persist according to its documentation.

Modify the classic redux-persist configuration as follows, including the deep-parse-json package:

  • Do not import redux-persist/lib/storage anymore, as we use an alternative storage.
  • Import redux-persist-nedb-storage:
import createNeDBStorage from 'redux-persist-nedb-storage'
import deepParseJson from 'deep-parse-json'
  • Modify the options for persistReducer in order to use the NeDB storage and set the deserialize option to deepParseJson:
const persistConfig = {
  key: 'root',
  storage: createNeDBStorage(),
  deserialize: deepParseJson
}

const persistedReducer = persistReducer(persistConfig, rootReducer)

You can pass options like below:

createNeDBStorage({
  databasePathname: 'mydb.db',
  inMemoryOnly: false
})