Coder Social home page Coder Social logo

memory-level's Introduction

memory-level

In-memory abstract-level database for Node.js and browsers, backed by a fully persistent red-black tree. The successor to memdown and level-mem.

๐Ÿ“Œ Which module should I use? What is abstract-level? Head over to the FAQ.

level badge npm Node version Test Coverage Standard Common Changelog Donate

Usage

If you are upgrading: please see UPGRADING.md.

const { MemoryLevel } = require('memory-level')

// Create a database
const db = new MemoryLevel({ valueEncoding: 'json' })

// Add an entry with key 'a' and value 1
await db.put('a', 1)

// Add multiple entries
await db.batch([{ type: 'put', key: 'b', value: 2 }])

// Get value of key 'a': 1
const value = await db.get('a')

// Iterate entries with keys that are greater than 'a'
for await (const [key, value] of db.iterator({ gt: 'a' })) {
  console.log(value) // 2
}

With callbacks:

db.put('example', { hello: 'world' }, (err) => {
  if (err) throw err

  db.get('example', (err, value) => {
    if (err) throw err
    console.log(value) // { hello: 'world' }
  })
})

API

The API of memory-level follows that of abstract-level with a one additional constructor option (see below). The createIfMissing and errorIfExists options of abstract-level are not relevant here. Data is discarded when the last reference to the database is released (i.e. db = null). Closing or reopening the database has no effect on the data. Data is not copied: when storing a Buffer value for example, subsequent mutations to that Buffer will affect the stored data too.

db = new MemoryLevel([options])

Besides abstract-level options, the optional options object may contain:

  • storeEncoding (string): one of 'buffer', 'view', 'utf8'. How to store data internally. This affects which data types can be stored non-destructively. The default is 'buffer' (that means Buffer) which is non-destructive. In browsers it may be preferable to use 'view' (Uint8Array) to be able to exclude the buffer shim. Or if there's no need to store binary data, then 'utf8' (String). Regardless of the storeEncoding, memory-level supports input that is of any of the aforementioned types, but internally converts it to one type in order to provide a consistent sort order.

Install

With npm do:

npm install memory-level

Contributing

Level/memory-level is an OPEN 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 the Contribution Guide for more details.

License

MIT

memory-level's People

Contributors

calvinmetcalf avatar dependabot[bot] avatar dominictarr avatar fanatid avatar greenkeeper[bot] avatar greenkeeperio-bot avatar juliangruber avatar kumavis avatar mafintosh avatar marcooliveira avatar marcuslyons avatar max-mapper avatar meirionhughes avatar mhart avatar nolanlawson avatar ralphtheninja avatar rvagg avatar timoxley avatar vweevers avatar willwhite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

memory-level's Issues

Question: How to use in browser?

Hi, I was wondering if thre are any examples somewhere on how to use it in a browser?
Is it just to bundle as UMD or ESM and then either use the script-tag or import it from a script?

Migrate functional-red-black-tree to Js-sdsl OrderedMap

Hey! I'm the developer of Js-sdsl. Official website: https://js-sdsl.github.io/

Now, we published the version 4.1.4.

I see you are using functional-red-black-tree.

In benchmark, we have confirmed that Js-sdsl is several times faster than functional-red-black-tree.

We would like to invite you to migrate red-black tree related functions to Js-sdsl v4.1.4 and I am willing to submit a pull request for this change.

Looking forward to your reply! :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.