Skip to content

Latest commit

 

History

History
129 lines (104 loc) · 3.82 KB

README_EN.md

File metadata and controls

129 lines (104 loc) · 3.82 KB

StoreDB

StoreDB is a web local database based on localStorage. You can store more complex data in localStorage easily and APIs-friendly(MongoDB like).

Why StoreDB?

  • StoreDB supports large data store and interaction in static webpage without database configuration. Anyone could easily build a powerful SPA(Single Page Application) with StoreDB.

  • StoreDB is suitable for the development of demo production. Imagine that you are participating in a marathon programming and time is so running out that you do not have time to set up a local/remote server and database configuration, all your team need is a show demo. Using StoreDB to implement data interaction could be a much better solution.

  • combination of AngularJS and StoreDB would be a much more powerful solution.

Example

EverFeed:Simple RSS reader

Tutorial

入门指南

Install

bower:

$ bower install storedb

HTML:

<script type="text/javascript" src="/path/to/storedb.js"></script>

Quick Start

Insert

Insert data into players set:

storedb('players').insert({"name":"Randy","sex":"male","score":20},function(err,result){
  if(!err){
    //do sth...
  } else //do sth...
})

Find

query data with the name as Randy in players collection

storedb('players').find({"name":"Randy"},function(err,result){
  if(!err){
    //use result to do sth...
  } else //do sth...
})

find all data by passing no parameter to the function

storedb('players').find()

List-type data would be returned from function

Update

update score value by increasing 10 with the name as Randy in player collection

storedb('players').update({"name":"Randy"},{"$inc":{"score":"10"}},function(err){
  if(!err){
    //do sth...
  } else //do sth...
})

You may have noticed that StoreDB has the MongoDB-style modifier! Check the modifier type out in API.

Remove

remove data with the name as Randy in players collection

storedb('players').remove({"name":"Randy"},function(err){
  if(!err){
    //do sth...
  } else //do sth...
})

remove all data in collection by passing no parameter to the function

storedb('players').remove()

APIs

storedb(collectionName)

  • collectionNamestring,automatically create if not exist。
.insert(newObj,callback)
  • newObjJSON object,插入的文档。
  • callbackfunction,包含参数errresult:无错误时err返回undefinedresult返回此次创建的文档对象。
  • 系统会自动为每一条文档创建unix时间戳id——_id,可通过callback中的result._id查看插入文档时所创建的id。
.find()
  • return Array,该集合所有文档。
.find(matchObj,callback)
  • matchObjJSON object,匹配的文档
  • callbackfunction,包含参数errresult:无错误时err返回undefinedresult返回查询结果数组。
.update(matchObj,upsert,callback)
  • matchObjJSON object,匹配的文档
  • upsertJSON object,对象中key应为修改器类型,value为修改对象。例如:
storedb('collectionA').update({"foo":"hi"},{"$set":{"bar":"hello"}},function(err){})
  • callbackfunction,包含参数err:无错误时err返回undefined

修改器类型:

  • $inc:为目标增加(或减小)对应数值
  • $set: 修改目标内容
  • $push:为目标数组插入对应元素
.remove()
  • 移除该集合所有文档
.remove(matchObj,callback)
  • matchObjJSON object,匹配的对应要删除的文档。
  • callbackfunction,包含参数err:无错误时err返回undefined

Donate

Alipay: djyde520@gmail.com