JsonDB是一个python实现的基于JSON格式的轻量级数据库开源项目,你可以通过github进行下载和安装,项目地址是:https://github.com/hujiang001/jsonDB/ 。
作者提供了完整的参考文档,而且是中文的,所以上手非常容易,这是他的中文文档的地址: https://github.com/hujiang001/jsonDB/wiki/reference-document 。 当前在项目工程里面也是包含了这个文档:reference.md。
项目还提供了一个使用的实例,在example.py中,下面我们把这个例子粘贴出来,上面有详细的注释,可以看出使用起来还是挺简单的:
#!usr/bin/env python
# -*- coding: utf-8 -*-
from database import JSONDB
if __name__=="__main__":
shopDb = JSONDB('shop_db',hashSize=1) #create shop db
userDb = JSONDB('sellerDb',hashSize=1) #create user db
#specify key
shopDb.ensureKey('shop',['id'])
shopDb.ensureKey('goods',['id'])
userDb.ensureKey('seller',['id','name'])
userDb.ensureKey('customer',['id','name'])
#for debugging, you can start perfDot and open debug switch
shopDb.perfDotStart()
userDb.perfDotStart()
shopDb.debugSwitch(1)
userDb.debugSwitch(1)
#insert data
#here we insert s