Coder Social home page Coder Social logo

mindb's Introduction

MinDBDatabase on JavaScript

Storing and structuring your application data on JavaScript.
Providing a standard Store Interface and Redis-like API that you can use in wherever.

Chinese version

Installation

Loading via script tag:

<script style="text/javascript" src="/path/to/script/min.js">

With node previously installed:

$ npm install min

If you are using component, you can install it with:

$ component install iwillwen/mindb

Basic Usage

Common key-value via such as SET, GET, etc.

min.set('foo', 'bar', function(err) {
  if (err) {
    return console.error(err);
  }
  
  min.get('foo', function(err, value) {
    if (err) {
      return console.error(err);
    }
    
    console.log(value); //=> bar
  });
});

Basic commands

  • set Set the value of a key (key, value[, callback])
  • setnx Set the value of a key, only if the key does not exist (key, value[, callback])
  • setex Set the value and expiration of a key (key, seconds, value[, callback])
  • psetex Set the value and expiration in milliseconds of a key (key, millseconds, value[, callback])
  • mset Set multiple keys to multiple values (plainObject[, callback])
  • msetnx Set multiple keys to multiple values, only if none of the keys exist (plainObject[, callback])
  • append Append a value to a key (key, value[, callback])
  • get Get the value of a key (key[, callback])
  • mget Get the values of a set of keys (keys[, callback])
  • getset Set the value of a key and return its old value (key, value[, callback])
  • strlen Get the length of a key (key[, callback])
  • incr Increment the integer value of a key by one (key[, callback])
  • incrby Increment the integer value of a key by the given amount (key, increment[, callback])
  • incrbyfloat Increment the float value of a key by the given amount (key, increment[, callback])

Hash, List, Set, Sorted Set

Maybe you can get the way by browsing Redis Commands. XD

Sweet

Nested Callbacks? Maybe you would prefer Promise:

min.incr('user_id')
  .then(function(curr) {
    return min.hmset('user-' + curr, {
      name: 'Will Wen Gunn',
      id: 'iwillwen',
      email: '[email protected]'
    });
  })
  .then(function(key) {
    var id = key.substr(5);
    
    return min.sadd('user-msg-' + id, 'WelCome!');
  })
  .then(function(length) {
    // ...
  })
  .catch(function(err) {
    console.log(err);
  });

Anymore else? How about MULTI?

min.multi()
  .incr('msg-seq')
  .incr('msg-seq')
  .incr('msg-seq')
  .exec(function(err, results) {
    if (err) {
      return console.error(err);
    }
    
    console.log(results); //=> [ [ 1 ], [ 2 ], [ 3 ] ]
  });

SWEET! Let's run to Harmony(ES2015)!

async _ => {
  var userId = await min.incr('users:id:seq')
  await min.hmset(`user:${userId}`, {
    name: 'Will Wen Gunn',
    sign: 'iwillwen',
    homepage: 'http://lifemap.in'
  })
  await min.sadd(`user:${userId}:msgs`, 'Welcome')
}

Support multiple databases:

var Min = min.fork();
Min.set('foo', 'bar')
  .then(/*...*/)
  .catch(/*...*/);

Store Interface

Read the Store Interface Documentation.

Contributing

Contribution is welcome.There are more than one way to contribute, and I will appreciate any way you choose.

  • tell your friends about iwillwen/mindb, let MinDB to be known
  • discuss MinDB, and submit bugs with github issues
  • send patch with github pull request
  • donate MinDB

Donate

Because of the Alipay donate page service had been stopped so if you want to support our job, please transfer to my Alipay account([email protected]) manually. Thanks. PayPal is welcome too: [email protected]

git-flow

We recommend you to use git-flow to make a patch.

Hint:

$ git flow feature start [featurename]
$ git add .
$ git commit -m 'new feature description'
$ git flow feature finish [featurename]

License

Copyright (c) 2012-2013 Will Wen Gunn([email protected]) All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

mindb's People

Contributors

iwillwen avatar viztor avatar kinogam avatar

Watchers

Seeker 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.