• Stars
    star
    330
  • Rank 127,657 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] Make localStorage do more things.

StoreDB

[DEPRECATED] Use localForage instead.

English version

StoreDB是一个基于localStorage的本地储存库,通过模拟MongoDB的一些API和概念(如“集(collection)”和“文档(document)”),使你能使用 localStorage 储存复杂数据。

Why StoreDB?

  • StoreDB使你在无须配置数据库的情况下,在静态页面中也能实现大量数据储存和交互。这意味着你能用StoreDB非常简便地建立一个功能强大的SPA(单页面应用,Single Page Application)。

  • StoreDB也适用于demo产品的开发。比如,假定你正在参加编程马拉松,你的团队只不过是想做出一个用以展示的demo,却不得不花费时间在远程或本地架设server,再配置数据库,白白浪费了宝贵的时间。使用StoreDB,你只需嵌入一段javascript代码就能实现丰富的数据交互。

  • 使用AngularJS配合StoreDB更是如虎添翼。

Demo

Everfeed - RSS Reader http://everfeed.ml/

MoniCoin - 比特币虚拟交易 http://djyde.github.io/MoniCoin

Tutorial

入门指南

Install

bower:

$ bower install storedb

HTML:

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

Quick Start

插入(Insert)

向名为players的集合中插入一条文档:

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

查询(Find)

查询players集合中nameRandy的文档:

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

如果需要查询集合中所有文档,将参数设置为空即可:

storedb('players').find()

函数将返回一个数组类型。

更新(Update)

players集合中nameRandyscore增加10

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

你可能已经注意到,StoreDB拥有和MongoDB一样的修改器!关于修改器类型请查看API

如果修改器为空,则默认为$set修改器:

storedb('players').update({"name":"Randy"}, {"sex":"male","name":"kriss"})

删除(Remove)

删除在players集合中nameRandy的一条文档:

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

如果要把整个集合删除,把参数设置为空:

storedb('players').remove()

APIs

storedb(collectionName)

  • collectionNamestring,需要操作的集合名。如果集合不存在,则自动创建。
.insert(newObj,callback)
  • newObjJSON object,插入的文档。
  • callbackfunction,包含参数errresult:无错误时err返回undefinedresult返回此次创建的文档对象。
  • 系统会自动为每一条文档创建unix时间戳id——_id,可通过callback中的result._id查看插入文档时所创建的id。
.find()
  • 返回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

由于支付宝取消支付页面,如果你支持 StoreDB,可以通过转账到我的支付宝账户 [email protected]

More Repositories

1

cusdis

lightweight, privacy-friendly alternative to Disqus.
TypeScript
2,421
star
2

WebShell

Bundle web apps to native OS X app
Swift
1,505
star
3

ToProgress

A lightweight top progress bar
JavaScript
524
star
4

V2EX-API

V2EX Non-official API list
369
star
5

Picas

Generate Wordmark Logo with Google Fonts
JavaScript
329
star
6

sinatine

weibo HTML5 for macOS
JavaScript
299
star
7

ossart

Print your GitHub activity as an artwork
TypeScript
212
star
8

sairin

Generate a blog from GitHub Issue
TypeScript
194
star
9

PureSlider

A lightweight, no-dependency image slider library
JavaScript
186
star
10

iCultus

Alternative menubar calendar for OS X
Vue
174
star
11

serlina

A progressive React serverside-rendering framework.
TypeScript
139
star
12

notepal

A simple tool to import/export your book note
TypeScript
132
star
13

Catchem

Buy APPs at the right time
JavaScript
114
star
14

koy

Markdown previewer
CSS
97
star
15

plastic-editor

A block-based editor
Svelte
90
star
16

cans

🍻 A framework for building React MobX application
JavaScript
83
star
17

WebClip

Plugable popup in browser.
HTML
71
star
18

nextjs-saas-starter

Nextjs SaaS boilerplate
TypeScript
67
star
19

snp

VS Code code snippet generator
Go
64
star
20

HotelX

typicode/hotel OS X menu bar app
Swift
60
star
21

V2HOT

[DEPRECATED] V2EX每日热议 for Android
Java
56
star
22

markbox

Parse your code in markdown into CodeSandbox.
TypeScript
52
star
23

Statut

Web application in OS X status bar
Swift
42
star
24

plastic

Another note app. Block based, bi-directional link, works on local.
Svelte
42
star
25

Pciano

Play pop piano on computer keyboard!
JavaScript
33
star
26

AMAzingTalk

和有经验的人一对一咨询
Nunjucks
33
star
27

We2EX

V2EX for Wechat App
JavaScript
30
star
28

node-maven

Getting maven repo url easily
JavaScript
29
star
29

everfeed

Simple RSS reader base on AngularJS & StoreDB
CSS
28
star
30

RocketLog

Bring console to terminal
JavaScript
26
star
31

front

A simple, hackable frontpage for hackers
JavaScript
25
star
32

MoniCoin

虚拟比特币交易
JavaScript
25
star
33

file-test

Test the generated directory structure and file content.
JavaScript
23
star
34

V2HOT-Plus

V2HOT Plus
Java
22
star
35

fullstack-nextjs-in-action

Book: Fullstack Next.js in Action
HTML
17
star
36

clean-nm

Clean your node_modules legacy 💩
JavaScript
17
star
37

ExMarket

Chinese Chrome Store(已停止更新)
JavaScript
16
star
38

node-baidu-translate

Baidu translate SDK for Node.js
JavaScript
15
star
39

esbin

Another jsbin but using ES Module
TypeScript
15
star
40

kge-desktop

全民k歌 for Desktop
TypeScript
15
star
41

fullstack-nextjs-in-action-example

TypeScript
14
star
42

MagPi

树莓派电子杂志MagPi中文翻译
13
star
43

rehux

React state management made simple
JavaScript
13
star
44

blog-2022

Astro
13
star
45

snippets

my personal code snippets
12
star
46

cown

Qiniu bucket manager and uploader
JavaScript
12
star
47

FilterAwesome

CSS filter library
CSS
11
star
48

binary-tree-visualizer

TypeScript
11
star
49

react-router-menu

Ant Design Menu React Router binding
TypeScript
11
star
50

blog-2017

new blog for 2017
Vue
9
star
51

tree-util

A library for working with n-ary tree
JavaScript
9
star
52

blog-2020

Nunjucks
9
star
53

docker-zimuzu

Zimuzu app Docker image
Dockerfile
9
star
54

icondog

An open-source icons manager for open-source icons
TypeScript
9
star
55

umi-plugin-autopolyfill

umi plugin for polyfill.io
JavaScript
8
star
56

TSpoon

Writing HammeSpoon scripts with TypeScript.
Lua
8
star
57

cusdis-telegram-bot

JavaScript
8
star
58

Todo4Realm

A simple todo app use Realm
Java
6
star
59

awesome-cusdis

6
star
60

awesome-sublime-packages

Collecting awesome sublime packages which speed up coding
6
star
61

lean-hook

JavaScript
6
star
62

hackernews-refinder

TypeScript
6
star
63

Synology_DS216j_Workshop

5
star
64

vue-native

5
star
65

eleventy-plugin-modern

JavaScript
5
star
66

sopa

Local package manager for web
JavaScript
5
star
67

push-if

push element to the array if true
JavaScript
5
star
68

vue-fundamentals

Building Large Application with Vue.js
Shell
4
star
69

genlink

Generate redirect link (in static way)
TypeScript
4
star
70

wechat-shell

Web Wechat on OS X
Swift
4
star
71

Gulliver

An android APP for managing time that taken by tripping.
Java
4
star
72

ama

Ask me anything!
3
star
73

note-app

TypeScript
3
star
74

React-Quill

Quilljs in React
JavaScript
3
star
75

parcel-typescript-tailwind

A boilerplate
HTML
3
star
76

graphql-jsonplaceholder

JavaScript
3
star
77

json2csv

Easy to use CSV generator
JavaScript
3
star
78

effective-apollo-antd

Created with CodeSandbox
TypeScript
3
star
79

djyde

2
star
80

node-earthlive

Earthlive wallpaper for Node.js
JavaScript
2
star
81

EasyTimer

A class to make Android timer task.
Java
2
star
82

AwesomeSheet

Frontend UIActionSheet
HTML
2
star
83

filefly

All CDN/OSS upload providers in one command.
JavaScript
2
star
84

aboutme

CSS
2
star
85

Repofo

A Chrome extension that show more informations about a Github repo.
JavaScript
2
star
86

jingyun

静云官网
CSS
2
star
87

ZhihuPlus

2
star
88

seamlessM4T-docker

Dockerfile
2
star
89

tronic

An Electron script runtime
TypeScript
2
star
90

unboxing

A tool for making scaffolding tool.
TypeScript
2
star
91

nextjs-sponsorkit

TypeScript
2
star
92

findRoad

JavaScript
2
star
93

smartclub

CSS
2
star
94

Maria

JavaScript
2
star
95

RIH

Organize your images resources
Vue
2
star
96

sql-hierarchy-example

TypeScript
2
star
97

NicoJS

Web Bubble
JavaScript
2
star
98

earthlivejs

Fetch photo of the earth every 5 minutes from himawari-8
JavaScript
2
star
99

legend-of-david-chiu

赌士列传: 老邱传奇
2
star
100

sao-tm

JavaScript
2
star