You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a file called index.js and enter the following:
importasyncstorageDownfrom'asyncstorage-down'importlevelupfrom'levelup'// or whichever implementation you're usingimportAsyncStoragefrom'@react-native-community/async-storage'constdb=levelup('/does/not/matter',{db: location=>asyncstorageDown(location,{ AsyncStorage })})db.put('name','Yuri Irsenovich Kim');db.put('dob','16 February 1941');db.put('spouse','Kim Young-sook');db.put('occupation','Clown');db.readStream().on('data',function(data){if(typeofdata.value!=='undefined'){console.log(data.key,'=',data.value);}}).on('error',function(err){console.log('Oh my!',err);}).on('close',function(){console.log('Stream closed');}).on('end',function(){console.log('Stream ended');});
Note
React Native's packager currently doesn't automatically inject browserified core node modules, like util, crypto, process, buffer, etc. Currently this module depends on several shims to mitigate the sadness. The alternative is to use react-native-webpack-server, which allows you to use browserified node core modules out of the box. Once React Native's packager allows the same functionality, this module's dependencies can be heavily pruned.
Alternatives
If you're willing to add native modules to your project, you may also be interested in react-native-leveldown, which implements native bindings to the original C++ implementation of LevelDB.