Code Monkey home page Code Monkey logo

localdb's Introduction

localDB.js

localDB.js provides couple of functions to interact with localStorage API. Inspired by mongoDB.

this methods are available

  • schema()
  • add()
  • remove()
  • update()
  • find()
  • findAll()
  • watch()
  • empty()
  • collections()

add localDB in your html file

<script src="localDB.js"></script>

Create schema(String, Array)

  localDB.schema("users", ["id", "username", "email", "age"]);
  localDB.schema("posts", ["title", "description", "userID"]);

add(String, Object) new item to your collection

  localDB.add("users", {
    id: 1
    username: "Max",
    email: "[email protected]",
    age: 34
  });

remove(String, Object) item from your collection

  localDB.remove('users', {is: {username: "max"}});
  
  //{is: {}} is like "==="
  //{not :{}} is like "!=="
  //{gt :{}} is like ">"
  //{gte :{}} is like ">="
  //{lt :{}} is like "<="
  //{lte :{}} is like "<="
  //{has :{arr: 32}} search for field in an array
  
  

update(String, Object, Object)

  localDB.update('users', {is: {username: "max"}}, {set: {age: 35 } );
  
  //if you have an array item you can use pull or push method
  localDB.update('users', {is: {username: "max"}}, {push: {arr: 34}} );
  localDB.update('users', {is: {username: "max"}}, {pull: {arr: 34}} );
  

find(String, Object)

  var cursor = localDB.find('users', {is: {username: 'max'}});
  //var cursor = localDB.find('users', {gt: {age: 30}});
  
  //find method return cursor object that contain this methods:
  cursor.count() //return number of your items
  cursor.fetch() // return an array
  cursor.limit() // limit(0, 5) return just five items
  cursor.where({not: {username: 'max'}}) // return cursor object
  
  

watch(String, Callback)

you can observe add, update and remove methods

  localDB.watch('add', function(obj, colname){
    //
  });
  
  localDB.watch('remove', function(obj, colname){
    //
  });
   
  localDB.watch('update', function(obj, colname){
    //
  });
  

empty(String) method delete all items in a collection

  localDB.empty(users);
  

collections() return entire database

  localDB.collections();
  

more

localdb's People

Contributors

alnv avatar

Watchers

James Cloos avatar  avatar

Forkers

lamouf

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.