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


Python Bucket.query方法代码示例

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


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

示例1: test_reject_ephemeral_attempt

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
 def test_reject_ephemeral_attempt(self):
     if not self._realserver_info:
         raise SkipTest("Need real server")
     admin=self.make_admin_connection()
     bucket_name = 'ephemeral'
     users=[('writer',('s3cr3t',[('data_reader', 'ephemeral'), ('data_writer', 'ephemeral')])),
            ('reader',('s3cr3t',[('data_reader', 'ephemeral')])),
            ('viewer',('s3cr3t',[('views_reader', 'ephemeral'), ('views_admin', 'ephemeral')]))]
     user=users[2]
     (userid, password, roles) = user[0],user[1][0],user[1][1]
     # add user
     try:
         admin.bucket_delete(bucket_name)
     except:
         pass
     try:
         admin.bucket_create(name=bucket_name,
                                  bucket_type='ephemeral',
                                  ram_quota=100)
     except HTTPError:
         raise SkipTest("Unable to provision ephemeral bucket")
     try:
         admin.user_upsert(AuthDomain.Local, userid, password, roles)
         admin.wait_ready(bucket_name, timeout=10)
         conn_str = "couchbase://{0}/{1}".format(self.cluster_info.host, bucket_name)
         bucket = Bucket(connection_string=conn_str,username=userid,password=password)
         self.assertIsNotNone(bucket)
         self.assertRaisesRegex(NotSupportedError, "Ephemeral", lambda: bucket.query("beer", "brewery_beers", streaming=True, limit=100))
     finally:
         admin.bucket_delete(bucket_name)
         admin.user_remove(AuthDomain.Local, userid)
开发者ID:couchbase,项目名称:couchbase-python-client,代码行数:33,代码来源:view_t.py

示例2: CBGen

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
class CBGen(CBAsyncGen):

    TIMEOUT = 10  # seconds

    def __init__(self, ssl_mode: str = 'none', n1ql_timeout: int = None, **kwargs):

        connection_string = 'couchbase://{host}/{bucket}?password={password}&{params}'
        connstr_params = parse.urlencode(kwargs["connstr_params"])

        if ssl_mode == 'data':
            connection_string = connection_string.replace('couchbase',
                                                          'couchbases')
            connection_string += '&certpath=root.pem'

        connection_string = connection_string.format(host=kwargs['host'],
                                                     bucket=kwargs['bucket'],
                                                     password=kwargs['password'],
                                                     params=connstr_params)

        self.client = Bucket(connection_string=connection_string)
        self.client.timeout = self.TIMEOUT
        if n1ql_timeout:
            self.client.n1ql_timeout = n1ql_timeout
        logger.info("Connection string: {}".format(connection_string))

    @quiet
    @backoff
    def create(self, *args, **kwargs):
        super().create(*args, **kwargs)

    @quiet
    @backoff
    @timeit
    def read(self, *args, **kwargs):
        super().read(*args, **kwargs)

    @quiet
    @backoff
    @timeit
    def update(self, *args, **kwargs):
        super().update(*args, **kwargs)

    @quiet
    def delete(self, *args, **kwargs):
        super().delete(*args, **kwargs)

    @timeit
    def view_query(self, ddoc: str, view: str, query: ViewQuery):
        tuple(self.client.query(ddoc, view, query=query))

    @quiet
    @timeit
    def n1ql_query(self, query: N1QLQuery):
        tuple(self.client.n1ql_query(query))
开发者ID:couchbase,项目名称:perfrunner,代码行数:56,代码来源:cbgen.py

示例3: getByView

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
 def getByView(self, parameter):
     bucket = Bucket(self._bucketUrl)
     options = Query()
     options.mapkey_range = (str(parameter), str(parameter))
     options.stale = False
     rows = bucket.query(self.designDocument, self._viewName, query=options)
     # the resulting row view from bucket.query is [key, value, docid, doc]
     # since we want docids, select the elements with index 2
     docids = [row[2] for row in rows]
     if len(docids) == 0:
         return []
     results = bucket.get_multi(docids).values()
     return [result.value for result in results]
开发者ID:lukedoolittle,项目名称:grokplus,代码行数:15,代码来源:repository.py

示例4: hello

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
def hello():
	try:
		from couchbase import Couchbase
		cb = Couchbase.connect(bucket='test_ZIZ')
		print cb
		c = Bucket('couchbase://localhost/test_ZIZ')

		resultset = c.query("dev_account", "all")
		print "------"
		print resultset
		print "------"

		# for row in resultset: print row.key
		return "Hello World!"
	except Exception as e:
		print "--------"
		print e
		print "--------"
开发者ID:alosiusrbt,项目名称:NoSql-Python,代码行数:20,代码来源:couchb.py

示例5: MatchHistoryUpdater

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
class MatchHistoryUpdater(object):
    def __init__(self):
        self.riot = riotwatcher.RiotWatcher(
            default_region=riotwatcher.EUROPE_WEST,
            key=os.environ.get('RIOT_API_KEY'))
        self.bucket = Bucket('couchbase://{}/{}'.format(
            os.environ.get('DB_HOST', 'localhost'),
            os.environ.get('DB_BUCKET_MATCH_HISTORY', 'match_history')
        ))

        self.players = self.get_players()
        logger_datapop.info('Setup complete')
        while True:
            for player in self.players:
                self.update_recent_games(player['id'])
                time.sleep(SLEEP_TIME)
            self.players = self.get_players()

    def get_players(self):
        players = [row.doc.value for row in self.bucket.query(
            'player', 'all_players', stale=False, include_docs=True)]
        return players

    def update_recent_games(self, player_id):
        api_matches = self.riot.get_recent_games(player_id)['games']
        for match in api_matches:
            match['summonerId'] = player_id
            key = 'Match::{}::{}'.format(player_id, match['gameId'])
            try:
                self.bucket.insert(key, match)
            except cb_exceptions.KeyExistsError:
                break

            try:
                full_match = self.riot.get_match(match_id=match['gameId'],
                                                 include_timeline=True)
                time.sleep(SLEEP_TIME)
            except Exception:
                continue
            else:
                full_match_key = 'Match::{}'.format(match['gameId'])
                self.bucket.upsert(full_match_key, full_match)
开发者ID:mattcarabine,项目名称:leaguebot,代码行数:44,代码来源:datapopulator.py

示例6: Bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
from couchbase.bucket import Bucket
from couchbase.views.parms import Query

STOCK_COUNT = 65348
RECEIPT_ITEM_COUNT = 1163469
BATCH_SIZE = 50000 #default size

BATCH_COUNT = RECEIPT_ITEM_COUNT / BATCH_SIZE
bucket = Bucket('couchbase://ec2-52-64-116-219.ap-southeast-2.compute.amazonaws.com/ReceiptItemSampe')
q = Query
q.limit = BATCH_SIZE

stock_view = bucket.query('id','idList', query = q)

key_list = []

for row in stock_view:
	key_list.append(row.key)
开发者ID:kenleyb,项目名称:CouchBomb,代码行数:20,代码来源:CouchBomb.py

示例7: CBGen

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
class CBGen(CBAsyncGen):

    NODES_UPDATE_INTERVAL = 15

    def __init__(self, **kwargs):
        self.client = Bucket('couchbase://{}:{}/{}'.format(
                kwargs['host'], kwargs.get('port', 8091), kwargs['bucket']),
                password=kwargs['password'])
        self.session = requests.Session()
        self.session.auth = (kwargs['username'], kwargs['password'])
        self.server_nodes = ['{}:{}'.format(kwargs['host'],
                                            kwargs.get('port', 8091))]
        self.nodes_url = 'http://{}:{}/pools/default/buckets/{}/nodes'.format(
            kwargs['host'],
            kwargs.get('port', 8091),
            kwargs['bucket'],
        )

    def start_updater(self):
        self.t = Thread(target=self._get_list_of_servers)
        self.t.daemon = True
        self.t.start()

    def _get_list_of_servers(self):
        while True:
            try:
                nodes = self.session.get(self.nodes_url).json()
            except Exception as e:
                logger.warn('Failed to get list of servers: {}'.format(e))
                continue
            self.server_nodes = [n['hostname'] for n in nodes['servers']]
            sleep(self.NODES_UPDATE_INTERVAL)

    @quiet
    def create(self, *args, **kwargs):
        super(CBGen, self).create(*args, **kwargs)

    @quiet
    def read(self, *args, **kwargs):
        super(CBGen, self).read(*args, **kwargs)

    @quiet
    def update(self, *args, **kwargs):
        super(CBGen, self).update(*args, **kwargs)

    @quiet
    def cas(self, *args, **kwargs):
        super(CBGen, self).cas(*args, **kwargs)

    @quiet
    def delete(self, *args, **kwargs):
        super(CBGen, self).delete(*args, **kwargs)

    def query(self, ddoc, view, query):
        node = choice(self.server_nodes).replace('8091', '8092')
        url = 'http://{}/{}/_design/{}/_view/{}?{}'.format(
            node, self.client.bucket, ddoc, view, query.encoded
        )
        t0 = time()
        resp = self.session.get(url=url)
        latency = time() - t0
        return resp.text, latency

    @quiet
    def lcb_query(self, ddoc, view, query):
        return tuple(self.client.query(ddoc, view, query=query))
开发者ID:EricACooper,项目名称:perfrunner,代码行数:68,代码来源:cbgen.py

示例8: range

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
    bm.design_create('search_keywords', DESIGN, use_devmode=False, syncwait=5)

NOUNS = ['cow', 'cat', 'dog', 'computer', 'WMD']
ADJECTIVES = ['happy', 'sad', 'thoughtful', 'extroverted']

kv = {}

for x in range(options.number_of_terms):
    n = random.choice(NOUNS)
    a = random.choice(ADJECTIVES)
    kv[" ".join([a, n])] = random.randint(1, 100000)

c.upsert_multi(kv)

vret = c.query('search_keywords',
               'top_keywords',
               limit=10,
               descending=True)

for row in vret:
    pprint.pprint(row, indent=4)

# Sample output:
#[   {   u'id': u'WMD sad', u'key': 92772, u'value': None},
#    {   u'id': u'WMD thoughtful', u'key': 76222, u'value': None},
#    {   u'id': u'cow happy', u'key': 71984, u'value': None},
#    {   u'id': u'computer sad', u'key': 68849, u'value': None},
#    {   u'id': u'cat thoughtful', u'key': 68417, u'value': None},
#    {   u'id': u'computer thoughtful', u'key': 67518, u'value': None},
#    {   u'id': u'dog thoughtful', u'key': 67350, u'value': None},
#    {   u'id': u'computer extroverted', u'key': 63279, u'value': None},
#    {   u'id': u'cow thoughtful', u'key': 60962, u'value': None},
开发者ID:Fabma,项目名称:couchbase-python-client,代码行数:34,代码来源:search_keywords.py

示例9: Bucket

# 需要导入模块: from couchbase.bucket import Bucket [as 别名]
# 或者: from couchbase.bucket.Bucket import query [as 别名]
# coding: UTF-8

from couchbase.bucket import Bucket
from couchbase.exceptions import CouchbaseError

c = Bucket('couchbase://localhost/default')

try:
    for row in c.query('example', 'person', limit=5, skip=0, startkey=[0, 10], endkey=[0, 40], descending=False):
        print unicode("{key}: {value}").format(key=row.key, value=row.value)

except CouchbaseError as e:
    print e
    raise
开发者ID:tucur-prg,项目名称:vagrant,代码行数:16,代码来源:query.py


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