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


Python Couchbase.create方法代码示例

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


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

示例1: TempDatabaseMixin

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import create [as 别名]
class TempDatabaseMixin(object):

    temp_dbs = None
    _db = None

    def setUp(self):
        self.server = Couchbase("localhost", "Administrator", "password")

    def tearDown(self):
        if self.temp_dbs:
            for name in self.temp_dbs:
                self.server.delete(name)

    def temp_db(self):
        if self.temp_dbs is None:
            self.temp_dbs = {}
        # Find an unused database name
        while True:
            name = "couchbase-mapping-python_%d" % random.randint(0, sys.maxint)
            if name not in self.temp_dbs:
                break
        db = self.server.create(name)
        self.temp_dbs[name] = db
        return name, db

    def del_db(self, name):
        del self.temp_dbs[name]
        self.server.delete(name)

    @property
    def db(self):
        if self._db is None:
            name, self._db = self.temp_db()
        return self._db
开发者ID:hdmessaging,项目名称:couchbase-mapping-python,代码行数:36,代码来源:testutil.py

示例2: test_old_unified_client_example

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import create [as 别名]
    def test_old_unified_client_example(self):
        from couchbase import Couchbase

        # connect to a couchbase server
        cb = Couchbase(self.host + ':' + self.port,
                       username=self.username,
                       password=self.password)
        if not cb.couch_api_base:
            raise SkipTest

        default_bucket = cb[self.bucket_name]
        default_bucket['key1'] = 'value1'

        default_bucket2 = cb.bucket(self.bucket_name)
        default_bucket2['key2'] = {'value': 'value2', 'expiration': 0}

        default_bucket.set('key3', 0, 0, 'value3')

        self.assertEqual(str(default_bucket.get('key1')[2]), 'value1')
        self.assertEqual(str(default_bucket2.get('key2')[2]), 'value2')
        self.assertEqual(str(default_bucket2['key3'][2]), 'value3')

        # create a new bucket
        try:
            newbucket = cb.create('newbucket', ram_quota_mb=100, replica=1)
        except:
            newbucket = cb['newbucket']

        # set a JSON document using the more "pythonic" interface
        newbucket['json_test'] = {'type': 'item', 'value': 'json test'}
        print 'json_test ' + str(newbucket['json_test'])
        # use the more verbose API which allows for setting expiration & flags
        newbucket.set('key4', 0, 0, {'type': 'item', 'value': 'json test'})
        print 'key4 ' + str(newbucket['key4'])

        design_doc = {"views":
                      {"all_by_types":
                       {"map":
                        '''function (doc, meta) {
                             emit([meta.type, doc.type, meta.id], doc.value);
                             // row output: ['json', 'item', 'key4'], 'json test'
                           }'''
                        },
                       },
                      }
        # save a design document
        newbucket['_design/testing'] = design_doc

        all_by_types_view = newbucket['_design/testing']['all_by_types']
        rows = all_by_types_view.results({'stale': False})
        for row in rows:
            self.assertTrue(row is not None)

        cb.delete('newbucket')
开发者ID:CanWeStudio,项目名称:couchbase-python-client,代码行数:56,代码来源:test_readme_examples.py

示例3: test_old_unified_client_example

# 需要导入模块: from couchbase import Couchbase [as 别名]
# 或者: from couchbase.Couchbase import create [as 别名]
    def test_old_unified_client_example(self):
        from couchbase import Couchbase

        # connect to a couchbase server
        cb = Couchbase(self.host + ":" + self.port, username=self.username, password=self.password)

        # create default bucket if it doesn't exist
        # try:
        #    cb.create(self.bucket_name)
        # except:
        #    pass

        default_bucket = cb[self.bucket_name]
        default_bucket["key1"] = "value1"

        default_bucket2 = cb.bucket(self.bucket_name)
        default_bucket2["key2"] = {"value": "value2", "expiration": 0, "flags": 10}

        default_bucket.set("key3", 0, 0, "value3")

        self.assertEqual(str(default_bucket.get("key1")[2]), "value1")
        self.assertEqual(str(default_bucket2.get("key2")[2]), "value2")
        self.assertEqual(str(default_bucket2["key3"][2]), "value3")

        # delete a bucket
        # cb.delete(self.bucket_name)
        # try:
        #    cb['default']
        # except Exception as ex:
        #    print ex

        # create a new bucket
        try:
            newbucket = cb.create("newbucket", ram_quota_mb=100, replica=1)
        except:
            newbucket = cb["newbucket"]

        # set a json document with a function
        # this will translate $flags and $expiration to memcached protocol
        # automatically generate the _id
        doc_id = newbucket.save({"type": "item", "value": "json test", "$flags": 25})
        print doc_id + " " + str(newbucket[doc_id])
        # use a provided _id
        doc_id = newbucket.save({"_id": "key4", "type": "item", "value": "json test", "$flags": 25})
        print doc_id + " " + str(newbucket[doc_id])

        design = {
            "_id": "_design/testing",
            "language": "javascript",
            "views": {"all": {"map": """function (doc) {\n    emit(doc, null);\n}"""}},
        }
        # save a design document
        # right now with no _rev, we can only create, we can't update
        try:
            doc_id = newbucket.save(design)
        except:
            doc_id = "_design/testing"

        if cb.couch_api_base:
            rows = newbucket.view("_design/testing/_view/all")
            for row in rows:
                self.assertTrue(row is not None)

        cb.delete("newbucket")
开发者ID:scalabl3,项目名称:couchbase-python-client,代码行数:66,代码来源:test_readme_examples.py


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