antoniopresto / react-native-local-mongodb

react-native local mongodb storage.
MIT License
304 stars 66 forks source link

custom storage with react-native-mmkv, need help. #75

Open abdullahIsa opened 2 years ago

abdullahIsa commented 2 years ago

Hello, need a bit of help i want to use another storage, i find react-native-mmkv good and fast, not sure if will improve performance but i want to give it a try, it seems to not work and throws an error, some of the storage functions I dont know yet how to get them from react-native-mmkv but may i know what the proper way to use this two together?

import {MMKV} from 'react-native-mmkv';
let options = {};
const StorageMMKV = {
  config: customOptions => {
    options = {
      ...options,
      ...customOptions,
    };
  },
  setItem: (key, value, cb) => {
    MMKV.set(key, value);
    cb(null, value);
  },
  multiSet: (value, cb) => {
    cb(null, value);
  },
  getItem: (key, cb) => {
    const value = MMKV.getString(key);
    cb(null, value);
  },
  removeItem: (key, cb) => {
    MMKV.delete(key);
    cb(null, key);
  },
  getAllKeys: cb => {
    const keys = MMKV.getAllKeys();
    cb(null, keys);
  },
  mergeItem: (key, cb) => {
    cb(null, key);
  },
  multiGet: (keys, cb) => {
    cb(null, keys);
  },
  multiSet: (keyValuePairs, cb) => {
    cb(null, keyValuePairs);
  },
  multiRemove: (keys, cb) => {
    cb(null, keys);
  },
  multiMerge: (keyValuePairs, cb) => {
    cb(null, keyValuePairs);
  },
  clear: cb => {
    MMKV.clearAll();
    cb(null, true);
  },
};
export {StorageMMKV};