Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
/memdownPublic archive

Superseded by memory-level. In-memory abstract-leveldown store for Node.js and browsers.

License

NotificationsYou must be signed in to change notification settings

Level/memdown

Repository files navigation

Superseded bymemory-level. Please seeFrequently Asked Questions.

Example

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.

Browser support

Sauce Test Status

Data types

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'})})

Snapshot guarantees

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.

Test

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

Contributing

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.

Big Thanks

Cross-browser Testing Platform and Open Source ♥ Provided bySauce Labs.

Sauce Labs logo

Donate

Support us with a monthly donation onOpen Collective and help us continue our work.

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp