- Notifications
You must be signed in to change notification settings - Fork37
Superseded by memory-level. In-memory abstract-leveldown store for Node.js and browsers.
License
Level/memdown
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Superseded bymemory-level
. Please seeFrequently Asked Questions.
If you are upgrading: please seeUPGRADING.md
.
constlevelup=require('levelup')constmemdown=require('memdown')constdb=levelup(memdown())db.put('hey','you',(err)=>{if(err)throwerrdb.get('hey',{asBuffer:false},(err,value)=>{if(err)throwerrconsole.log(value)// 'you'})})
Withasync/await
:
awaitdb.put('hey','you')constvalue=awaitdb.get('hey',{asBuffer:false})
Your data is discarded when the process ends or you release a reference to the store. Note as well, though the internals ofmemdown
operate synchronously -levelup
does not.
Keys and values can be strings or Buffers. Any other key type will be irreversibly stringified. The only exceptions arenull
andundefined
. Keys and values of that type are rejected.
constdb=levelup(memdown())db.put('example',123,(err)=>{if(err)throwerrdb.createReadStream({keyAsBuffer:false,valueAsBuffer:false}).on('data',(entry)=>{console.log(typeofentry.key)// 'string'console.log(typeofentry.value)// 'string'})})
If you desire non-destructive encoding (e.g. to store and retrieve numbers as-is), wrapmemdown
withencoding-down
. Alternatively installlevel-mem
which conveniently bundleslevelup
,memdown
andencoding-down
. Such an approach is also recommended if you want to achieve universal (isomorphic) behavior. For example, you could haveleveldown
in a backend andmemdown
in the frontend.
constencode=require('encoding-down')constdb=levelup(encode(memdown(),{valueEncoding:'json'}))db.put('example',123,(err)=>{if(err)throwerrdb.createReadStream({keyAsBuffer:false,valueAsBuffer:false}).on('data',(entry)=>{console.log(typeofentry.key)// 'string'console.log(typeofentry.value)// 'number'})})
Amemdown
store is backed bya fully persistent data structure and thus has snapshot guarantees. Meaning that reads operate on a snapshot in time, unaffected by simultaneous writes.
In addition to the regularnpm test
, you can testmemdown
in a browser of choice with:
npm run test-browser-local
To check code coverage:
npm run coverage
Level/memdown
is anOPEN Open Source Project. This means that:
Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
See theContribution Guide for more details.
Cross-browser Testing Platform and Open Source ♥ Provided bySauce Labs.
Support us with a monthly donation onOpen Collective and help us continue our work.
About
Superseded by memory-level. In-memory abstract-leveldown store for Node.js and browsers.