Code Monkey home page Code Monkey logo

memory-key-value-store's Introduction

memory-key-value-store

In Memory Key Value Datastore with option to associate multiple keys to an object and object keys

npm install --save memory-key-value-store

Example Usage

const memoryKeyValueStore = require('memory-key-value-store');

const store = memoryKeyValueStore();

store.set('a', { foo: 'bar' });
store.find('a');

API

Note that in all cases, simple javascript objects as well as numbers can be used for keys. All keys get converted to strings internally. Javascript objects are serialized using json-stable-stringify

Also note that values should always be javascript objects if you intend on using the save method.

Methods

find

Find item by its key. Returns null if item is not found.

store.find('a');

save

Create a new item, or extend the old one.

store.save('a', { foo: 'bar', ball: 'baz' });
store.save('a', { ball: 'bash', car: 'mash' });
// the final value is: { foo: 'bar', ball: 'bash', car: 'mash' }

set

Create a new item or replace the old one.

store.set('a', { foo: 'bar', ball: 'baz' });
store.set('a', { ball: 'bash', car: 'mash' });
// the final value is: { ball: 'bash', car: 'mash' }

delete

Delete an item by its key (has no effect if the item doesnt already exist)

store.delete('a');

secondaryKey

Associate two keys with a reference to the same value. This will cause subsequent calls to edit the values of either key to edit the values of both keys.

store.secondaryKey('a', 'b');
store.set('a', { foo: 'bar' });
// the value of "b" is now also { foo: 'bar' }

You can optionally associate an array of keys with the original

store.secondaryKey('a', ['b', 'c']);

Method Chaining

The methods: save, set, delete, and secondaryKey can be chained

store.save('a', { foo: 'bar' })
  .set('b', { ball: 'baz' })
  .delete('a')
  .secondaryKey('b', 'c');

Development

To setup the development environment and run tests:

  1. npm install
  2. flow-typed install
  3. gulp test

memory-key-value-store's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.