本文整理汇总了Python中couchdb.client.Server.save方法的典型用法代码示例。如果您正苦于以下问题:Python Server.save方法的具体用法?Python Server.save怎么用?Python Server.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类couchdb.client.Server
的用法示例。
在下文中一共展示了Server.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_couch_database_for_test
# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import save [as 别名]
def copy_couch_database_for_test(test, db):
port = str(test.wrapper.port)
couch_url = 'http://localhost:' + port
new_dbname = db._replica_uid + '_copy'
new_db = couch.CouchDatabase.open_database(
urljoin(couch_url, new_dbname),
create=True,
replica_uid=db._replica_uid or 'test')
# copy all docs
session = couch.Session()
old_couch_db = Server(couch_url, session=session)[db._replica_uid]
new_couch_db = Server(couch_url, session=session)[new_dbname]
for doc_id in old_couch_db:
doc = old_couch_db.get(doc_id)
# bypass u1db_config document
if doc_id == 'u1db_config':
pass
# copy design docs
elif doc_id.startswith('_design'):
del doc['_rev']
new_couch_db.save(doc)
# copy u1db docs
elif 'u1db_rev' in doc:
new_doc = {
'_id': doc['_id'],
'u1db_transactions': doc['u1db_transactions'],
'u1db_rev': doc['u1db_rev']
}
attachments = []
if ('u1db_conflicts' in doc):
new_doc['u1db_conflicts'] = doc['u1db_conflicts']
for c_rev in doc['u1db_conflicts']:
attachments.append('u1db_conflict_%s' % c_rev)
new_couch_db.save(new_doc)
# save conflict data
attachments.append('u1db_content')
for att_name in attachments:
att = old_couch_db.get_attachment(doc_id, att_name)
if (att is not None):
new_couch_db.put_attachment(new_doc, att,
filename=att_name)
# cleanup connections to prevent file descriptor leaking
return new_db
示例2: copy_couch_database_for_test
# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import save [as 别名]
def copy_couch_database_for_test(test, db):
port = str(test.wrapper.port)
couch_url = "http://localhost:" + port
new_dbname = db._replica_uid + "_copy"
new_db = couch.CouchDatabase.open_database(
urljoin(couch_url, new_dbname), create=True, replica_uid=db._replica_uid or "test"
)
# copy all docs
session = couch.Session()
old_couch_db = Server(couch_url, session=session)[db._replica_uid]
new_couch_db = Server(couch_url, session=session)[new_dbname]
for doc_id in old_couch_db:
doc = old_couch_db.get(doc_id)
# bypass u1db_config document
if doc_id == "u1db_config":
pass
# copy design docs
elif doc_id.startswith("_design"):
del doc["_rev"]
new_couch_db.save(doc)
# copy u1db docs
elif "u1db_rev" in doc:
new_doc = {"_id": doc["_id"], "u1db_transactions": doc["u1db_transactions"], "u1db_rev": doc["u1db_rev"]}
attachments = []
if "u1db_conflicts" in doc:
new_doc["u1db_conflicts"] = doc["u1db_conflicts"]
for c_rev in doc["u1db_conflicts"]:
attachments.append("u1db_conflict_%s" % c_rev)
new_couch_db.save(new_doc)
# save conflict data
attachments.append("u1db_content")
for att_name in attachments:
att = old_couch_db.get_attachment(doc_id, att_name)
if att is not None:
new_couch_db.put_attachment(new_doc, att, filename=att_name)
# cleanup connections to prevent file descriptor leaking
return new_db