python的couchdb驱动程序。
time2relax的Python项目详细描述
time2relax:python couchdb驱动程序
< Buff行情>python的couchdb驱动程序。
time2relax是一个python驱动程序,它试图在您和couchdb之间提供最低级别的抽象。
基本插入用法:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]><细节>
- 功能支持
- 安装
- 文档
- 如何贡献
<;small>;使用markdown-toc生成的目录<;/small>;
<详细内容>功能支持
受pouchdb和couchdb nanoapi的启发,它的特点是:
time2relax正式支持python 2.7和3.6+
安装
要安装Time2Relax,只需运行:
$ pip install -U time2relax
✨?✨
文档
有关详细文档,请访问https://time2relax.readthedocs.org" rel="nofollow">https://time2relax.readthedocs.org
在项目中使用time2relax:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')
大部分api公开为db.function(*args,**kwargs)
,其中**kwargs
是可选参数,可以接受请求。session.request
请求。
创建数据库
最初,couchdb
对象将检查数据库是否存在,如果不存在,则尝试创建数据库。您可以使用create_db=false
跳过此步骤:
>>>db=CouchDB('http://localhost:5984/dbname',create_db=False)
删除数据库
删除数据库:
>>>db.destroy()<Response[200]>
使用couchdb
对象的进一步请求应引发time2relax.resourcenotfound
:
>>>db.info()ResourceNotFound:({'error':'not_found','reason':'missing'},<Response[404]>)
创建/更新文档
注意:对文档的有效属性名有一些couchdb限制。
创建新文档:
>>>db.insert({'_id':'docid','title':'Heros'})<Response[201]>
创建新文档并让couchdb自动为其生成\u id
:
>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>
如果文档已存在,则必须指定其修订版\u rev
,否则将发生冲突。您可以使用\u rev
:
>>>result=db.get('docid').json()>>>db.insert({'_id':result['_id'],'_rev':result['_rev'],'title':'Dance'})<Response[201]>
获取文档
检索文档:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>0
删除文档
您必须提供现有文档的\u rev
。
删除文档:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>1
您还可以使用time2relax.couchdb.insert
和{"u deleted":true}
:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>2
创建/更新一批文档
创建多个文档:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>3
如果忽略给定文档上的\u id
参数,数据库将创建一个新文档并为您分配id:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>4
要更新文档,必须同时包含一个\u id
参数和一个\u rev
参数,该参数应与更新所依据的文档的id和修订相匹配:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>5
最后,要删除文档,请包含一个值为true的
参数:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>6
获取一批文档
获取多个文档:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>7
您可以使用startkey
/endkey
查找范围内的所有文档:
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>8
您还可以使用特殊的高Unicode字符进行前缀搜索,即"给我所有\u id
以'foo'
开头的文档":
>>>fromtime2relaximportCouchDB>>>db=CouchDB('http://localhost:5984/dbname')>>>db.insert({'title':'Ziggy Stardust'})<Response[201]>9
复制数据库
注意:目标必须存在,可以在复制之前使用json={'create_target':true}
创建它。
将数据库复制到目标:
$ pip install -U time2relax
✨?✨
0
保存附件
此方法将更新现有文档以添加附件,因此如果该文档已存在,则需要\u rev
。如果文档不存在,则此方法将创建包含附件的空文档。
附加文本/普通文件:
$ pip install -U time2relax
✨?✨
1
获取附件
获取附件数据:
$ pip install -U time2relax
✨?✨
2
删除附件
您必须提供现有文档的\u rev
。
删除附件:
$ pip install -U time2relax
✨?✨
3
获取数据库信息
获取有关数据库的信息:
$ pip install -U time2relax
✨?✨
4
压缩数据库
这通过删除未使用的和旧的数据(即那些修订不再引用的非叶修订和附件)来减小数据库的大小。
触发压缩操作:
$ pip install -U time2relax
✨?✨
5
运行列表函数
马克斯确保您理解list函数在couchdb中的工作方式。一个好的开始是列表上的couchdb指南条目:$ pip install -U time2relax
✨?✨
6
运行显示功能
确保您理解show函数在couchdb中是如何工作的。一个好的开始是在shows上的couchdb guide条目 确保您理解视图函数在couchdb中是如何工作的。一个好的开始是关于视图的couchdb guide条目
7
$ pip install -U time2relax
✨?✨
运行查看功能
8
$ pip install -U time2relax
✨?✨
如何贡献
版本历史记录
0.5.0(2018-08-04)
time2relax.time2relax
0.4.1(2017-11-22)
0.4.0(2017-11-21)
couchdberror
现在是httperror
(向后不兼容)couchdb(skip_setup=false)
现在是couchdb(create_db=true)
(向后不兼容)0.3.0(2017-03-03)
请求
包装器。
列表
,显示
,视图
0.2.0(2016-12-10)
0.1.0(2016-12-10)
推荐PyPI第三方库