纯用python(python 3 fork)编写的面向文档的数据库。
blitzdb3的Python项目详细描述
闪电战-DB3
blitzdb3是blitzdb到python 3的端口。我们在一些内部项目上使用blitzdb,这些项目位于abilian,需要进行这些更改才能将这些项目迁移到python 3。
blitzdb或blitz是一个纯用python编写的基于文档的、面向对象的事务性数据库。此外,它还提供了功能强大的查询语言、文档深度索引、压缩数据存储和嵌入式文档自动引用。它相当快,可以很容易地嵌入到任何python应用程序中,并且没有任何外部依赖项(使用第三方后端时除外)。此外,您还可以将其作为前端用于其他数据库引擎,如MongoDB,以防需要更多电源。
主要功能
- 基于文档的、面向对象的界面。
- 强大而丰富的查询语言。
- 任意字段上的深层文档索引。
- 文件的压缩存储。
- 支持多个后端(例如基于文件的存储、MongoDB)。
- 支持数据库事务(目前仅限于基于文件的后端)。
用例
blitz可以用作客户端应用程序的独立文档存储。最初,blitz设计用于checkmate的python代码分析工具包,其中存储了统计数据。由于blitz将所有文档存储为单个json文件,因此可以对整个数据库进行版本控制。
安装
安装blitz最简单的方法是通过pip或轻松安装
有关更详细的安装说明,请参阅文档 此项目的详细文档位于readthedocs上,请随意查看! 感谢您的所有贡献,没有您,BlitzDB将不再是今天的样子:) 为了了解闪电战的作用,这里有一些例子。pip install blitzdb
#or...
easy_install blitzdb
详细文档
路线图
更改日志
旧变更日志(Andreas Dewes原创的BlitzDB/Andreas@7scientists.com)
文档的适当属性迭代的支持
document.meta
属性设置集合
参数。get
,有u键和
clear
方法来文档
类贡献者(按字母顺序)
现役维修人员(闪电战3)
原作者(blitzdb)
原始贡献者
第三方贡献
示例
创建对象
fromblitzdbimportDocumentclassMovie(Document):passclassActor(Document):passthe_godfather=Movie({'name':'The Godfather','year':1972,'pk':1})marlon_brando=Actor({'name':'Marlon Brando','pk':1})al_pacino=Actor({'name':'Al Pacino','pk':1})
在数据库中存储对象:
fromblitzdbimportFileBackendbackend=FileBackend("/path/to/my/db")the_godfather.save(backend)marlon_brando.save(backend)al_pacino.save(backend)
从数据库检索对象:
the_godfather=backend.get(Movie,{'pk':1})#or...the_godfather=backend.get(Movie,{'name':'The Godfather'})
过滤对象
movies_from_1972=backend.filter(Movie,{'year':1972})
处理事务
backend.begin()the_godfather.director='Roland Emmerich'#oops...the_godfather.save()backend.rollback()#undo the changes...
创建嵌套对象引用
the_godfather.cast={'Don Vito Corleone':marlon_brando,'Michael Corleone':al_pacino}#Documents stored within other objects will be automatically converted to database references.marlon_brando.performances=[the_godfather]al_pacino.performances=[the_godfather]marlon_brando.save(backend)al_pacino.save(backend)the_godfather.save(backend)#Will store references to the movies within the documents in the DB
创建数据库索引和高级查询
backend.create_index(Actor,'performances')#Will create an index on the 'performances' field, for fast queryinggodfather_cast=backend.filter(Actor,{'movies':the_godfather})#Will return 'Al Pacino' and 'Marlon Brando'
任意过滤器表达式
star_wars_iv=Movie({'name':'Star Wars - Episode IV: A New Hope','year':1977})star_wars_iv.save()movies_from_the_seventies=backend.filter(Movie,{'year':lambdayear:year>=1970andyear<1980})#Will return Star Wars & The Godfather (man, what a decade!)
推荐PyPI第三方库