当前位置: 首页>>代码示例>>Python>>正文


Python Server.delete方法代码示例

本文整理汇总了Python中couchdb.Server.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Server.delete方法的具体用法?Python Server.delete怎么用?Python Server.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchdb.Server的用法示例。


在下文中一共展示了Server.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove_db

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import delete [as 别名]
def remove_db(database):
    '''
    Destroy given database.
    '''
    server = Server('http://localhost:5984/')
    server.delete(database)
    logger.info('[DB] Local database %s removed' % database)
开发者ID:poupotte,项目名称:couchdb-fuse,代码行数:9,代码来源:dbutils.py

示例2: remove_db

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import delete [as 别名]
def remove_db(database):
    '''
    Destroy given database.
    '''
    server = Server('http://localhost:5984/')
    try:
        server.delete(database)
    except http.ResourceNotFound:
        logger.info('[DB] Local database %s already removed' % database)
    logger.info('[DB] Local database %s removed' % database)
开发者ID:Kloadut,项目名称:cozy-fuse-linux,代码行数:12,代码来源:dbutils.py

示例3: Server

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import delete [as 别名]
func_list = ['getBudgetAccount', 'getBudgetAggregate', 'getReceiptAccount', 'getReceiptAggregate', 'getPopulation', 'getGDP', 'getDebt', 'getTaxRates', 'getInflation']

parser = argparse.ArgumentParser() #formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('f', metavar='FUNCTION', type=str, help='function', choices=func_list)
parser.add_argument('-p', '--port', metavar='NUM', type=int, help='couchdb port', default=5984)
parser.add_argument('-s', '--host', metavar='NAME', type=str, help='couchdb host', default='localhost')
parser.add_argument('-d', '--db', metavar='NAME', type=str, help='database name', default='tax')
parser.add_argument('-r', '--recreate', action="store_true", help='recreate database', default=False)
parser.add_argument('-c', '--create', action="store_true", help='create database', default=False)
parser.add_argument('-a', '--args', action="append", help='additional arguments', default=[], nargs=2)

args = parser.parse_args()
serv = Server('http://{0}:{1}/'.format(args.host, args.port))
if args.recreate:
    try:
        serv.delete(args.db)
    except:
        pass

if args.create or args.recreate:
    try:
        serv.create(args.db)
    except Exception as e:
        if not isinstance(e, PreconditionFailed):
            print 'Error creating database:', e
            exit(-1)

try:
    db = serv[args.db]
except:
    print 'Database does not exist!'
开发者ID:Iskratgz,项目名称:nosql-tutorial,代码行数:33,代码来源:whatwepayfor.py

示例4: CouchTests

# 需要导入模块: from couchdb import Server [as 别名]
# 或者: from couchdb.Server import delete [as 别名]
class CouchTests(unittest.TestCase):

    def setUp(self):
        uri = os.environ.get('COUCHDB_URI', 'http://localhost:5984/')
        self.cache_dir = tempfile.mkdtemp(prefix='couchdb')
        self.server = Server(uri, cache=self.cache_dir)
        try:
            self.server.delete('python-tests')
        except client.ResourceNotFound:
            pass
        self.db = self.server.create('python-tests')

    def tearDown(self):
        try:
            self.server.delete('python-tests')
        except client.ResourceNotFound:
            pass
        shutil.rmtree(self.cache_dir)

    def _create_test_docs(self, num):
        for i in range(num):
            self.db[str(i)] = {'a': i + 1, 'b': (i + 1) ** 2}

    def test_basics(self):
        self.assertEqual(0, len(self.db))

        # create a document
        data = {'a': 1, 'b': 1}
        self.db['0'] = data
        self.assertEqual('0', data['_id'])
        assert '_rev' in data
        doc = self.db['0']
        self.assertEqual('0', doc.id)
        self.assertEqual(data['_rev'], doc.rev)
        self.assertEqual(1, len(self.db))

        # delete a document
        del self.db['0']
        self.assertRaises(ResourceNotFound, self.db.__getitem__, '0')

        # test _all_docs
        self._create_test_docs(4)
        self.assertEqual(4, len(self.db))
        for doc_id in self.db:
            assert int(doc_id) in range(4)

        # test a simple query
        query = """function(doc) {
            if (doc.a==4)
                emit(null, doc.b);
        }"""
        result = list(self.db.query(query))
        self.assertEqual(1, len(result))
        self.assertEqual('3', result[0].id)
        self.assertEqual(16, result[0].value)

        # modify a document, and redo the query
        doc = self.db['0']
        doc['a'] = 4
        self.db['0'] = doc
        result = list(self.db.query(query))
        self.assertEqual(2, len(result))

        # add more documents, and redo the query again
        self.db.create({'a': 3, 'b': 9})
        self.db.create({'a': 4, 'b': 16})
        result = list(self.db.query(query))
        self.assertEqual(3, len(result))
        self.assertEqual(6, len(self.db))

        # delete a document, and redo the query once more
        del self.db['0']
        result = list(self.db.query(query))
        self.assertEqual(2, len(result))
        self.assertEqual(5, len(self.db))

    def test_conflict_detection(self):
        doc1 = {'a': 1, 'b': 1}
        self.db['foo'] = doc1
        doc2 = self.db['foo']
        self.assertEqual(doc1['_id'], doc2.id)
        self.assertEqual(doc1['_rev'], doc2.rev)

        # make conflicting modifications
        doc1['a'] = 2
        doc2['a'] = 3
        self.db['foo'] = doc1
        self.assertRaises(ResourceConflict, self.db.__setitem__, 'foo', doc2)

        # try submitting without the revision info
        data = {'_id': 'foo', 'a': 3, 'b': 1}
        self.assertRaises(ResourceConflict, self.db.__setitem__, 'foo', data)

        del self.db['foo']
        self.db['foo'] = data

    def test_lots_of_docs(self):
        num = 100 # Crank up manually to really test
        for i in range(num): 
            self.db[str(i)] = {'integer': i, 'string': str(i)}
#.........这里部分代码省略.........
开发者ID:ligthyear,项目名称:couchdb-python,代码行数:103,代码来源:couch_tests.py


注:本文中的couchdb.Server.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。