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


Python Item.load方法代码示例

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


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

示例1: _query

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def _query(
        self, limit=None, index=None, reverse=False, consistent=False, exclusive_start_key=None, **filter_kwargs
    ):
        """
        The internal method that performs the actual queries. Used extensively
        by ``ResultSet`` to perform each (paginated) request.
        """
        kwargs = {"limit": limit, "index_name": index, "scan_index_forward": reverse, "consistent_read": consistent}

        if exclusive_start_key:
            kwargs["exclusive_start_key"] = {}

            for key, value in exclusive_start_key.items():
                kwargs["exclusive_start_key"][key] = self._dynamizer.encode(value)

        # Convert the filters into something we can actually use.
        kwargs["key_conditions"] = self._build_filters(filter_kwargs, using=QUERY_OPERATORS)

        raw_results = self.connection.query(self.table_name, **kwargs)
        results = []
        last_key = None

        for raw_item in raw_results.get("Items", []):
            item = Item(self)
            item.load({"Item": raw_item})
            results.append(item)

        if raw_results.get("LastEvaluatedKey", None):
            last_key = {}

            for key, value in raw_results["LastEvaluatedKey"].items():
                last_key[key] = self._dynamizer.decode(value)

        return {"results": results, "last_key": last_key}
开发者ID:9seconds,项目名称:boto,代码行数:36,代码来源:table.py

示例2: _scan

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def _scan(self, limit=None, exclusive_start_key=None, segment=None, total_segments=None, **filter_kwargs):
        """
        The internal method that performs the actual scan. Used extensively
        by ``ResultSet`` to perform each (paginated) request.
        """
        kwargs = {"limit": limit, "segment": segment, "total_segments": total_segments}

        if exclusive_start_key:
            kwargs["exclusive_start_key"] = {}

            for key, value in exclusive_start_key.items():
                kwargs["exclusive_start_key"][key] = self._dynamizer.encode(value)

        # Convert the filters into something we can actually use.
        kwargs["scan_filter"] = self._build_filters(filter_kwargs, using=FILTER_OPERATORS)

        raw_results = self.connection.scan(self.table_name, **kwargs)
        results = []
        last_key = None

        for raw_item in raw_results.get("Items", []):
            item = Item(self)
            item.load({"Item": raw_item})
            results.append(item)

        if raw_results.get("LastEvaluatedKey", None):
            last_key = {}

            for key, value in raw_results["LastEvaluatedKey"].items():
                last_key[key] = self._dynamizer.decode(value)

        return {"results": results, "last_key": last_key}
开发者ID:kolencherry,项目名称:dd-agent,代码行数:34,代码来源:table.py

示例3: get_item

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def get_item(self, consistent=False, attributes=None, **kwargs):
        """
        Fetches an item (record) from a table in DynamoDB.

        To specify the key of the item you'd like to get, you can specify the
        key attributes as kwargs.

        Optionally accepts a ``consistent`` parameter, which should be a
        boolean. If you provide ``True``, it will perform
        a consistent (but more expensive) read from DynamoDB.
        (Default: ``False``)

        Optionally accepts an ``attributes`` parameter, which should be a
        list of fieldname to fetch. (Default: ``None``, which means all fields
        should be fetched)

        Returns an ``Item`` instance containing all the data for that record.

        Example::

            # A simple hash key.
            >>> john = users.get_item(username='johndoe')
            >>> john['first_name']
            'John'

            # A complex hash+range key.
            >>> john = users.get_item(username='johndoe', last_name='Doe')
            >>> john['first_name']
            'John'

            # A consistent read (assuming the data might have just changed).
            >>> john = users.get_item(username='johndoe', consistent=True)
            >>> john['first_name']
            'Johann'

            # With a key that is an invalid variable name in Python.
            # Also, assumes a different schema than previous examples.
            >>> john = users.get_item(**{
            ...     'date-joined': 127549192,
            ... })
            >>> john['first_name']
            'John'

        """
        raw_key = self._encode_keys(kwargs)
        item_data = self.connection.get_item(
            self.table_name,
            raw_key,
            attributes_to_get=attributes,
            consistent_read=consistent
        )
        if 'Item' not in item_data:
            raise exceptions.ItemNotFound("Item %s couldn't be found." % kwargs)
        item = Item(self)
        item.load(item_data)
        return item
开发者ID:B-Rich,项目名称:boto,代码行数:58,代码来源:table.py

示例4: _query

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def _query(self, limit=None, index=None, reverse=False, consistent=False,
               exclusive_start_key=None, select=None, attributes_to_get=None,
               **filter_kwargs):
        """
        The internal method that performs the actual queries. Used extensively
        by ``ResultSet`` to perform each (paginated) request.
        """
        kwargs = {
            'limit': limit,
            'index_name': index,
            'consistent_read': consistent,
            'select': select,
            'attributes_to_get': attributes_to_get,
        }

        if reverse:
            kwargs['scan_index_forward'] = False

        if exclusive_start_key:
            kwargs['exclusive_start_key'] = {}

            for key, value in exclusive_start_key.items():
                kwargs['exclusive_start_key'][key] = \
                    self._dynamizer.encode(value)

        # Convert the filters into something we can actually use.
        kwargs['key_conditions'] = self._build_filters(
            filter_kwargs,
            using=QUERY_OPERATORS
        )

        raw_results = self.connection.query(
            self.table_name,
            **kwargs
        )
        results = []
        last_key = None

        for raw_item in raw_results.get('Items', []):
            item = Item(self)
            item.load({
                'Item': raw_item,
            })
            results.append(item)

        if raw_results.get('LastEvaluatedKey', None):
            last_key = {}

            for key, value in raw_results['LastEvaluatedKey'].items():
                last_key[key] = self._dynamizer.decode(value)

        return {
            'results': results,
            'last_key': last_key,
        }
开发者ID:Revmetrix,项目名称:boto,代码行数:57,代码来源:table.py

示例5: _batch_get

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def _batch_get(self, keys, consistent=False):
        """
        The internal method that performs the actual batch get. Used extensively
        by ``BatchGetResultSet`` to perform each (paginated) request.
        """
        items = {
            self.table_name: {
                'Keys': [],
            },
        }

        if consistent:
            items[self.table_name]['ConsistentRead'] = True

        for key_data in keys:
            raw_key = {}

            for key, value in key_data.items():
                raw_key[key] = self._dynamizer.encode(value)

            items[self.table_name]['Keys'].append(raw_key)

        raw_results = self.connection.batch_get_item(request_items=items)
        results = []
        unprocessed_keys = []

        for raw_item in raw_results['Responses'].get(self.table_name, []):
            item = Item(self)
            item.load({
                'Item': raw_item,
            })
            results.append(item)

        raw_unproccessed = raw_results.get('UnprocessedKeys', {})

        for raw_key in raw_unproccessed.get('Keys', []):
            py_key = {}

            for key, value in raw_key.items():
                py_key[key] = self._dynamizer.decode(value)

            unprocessed_keys.append(py_key)

        return {
            'results': results,
            # NEVER return a ``last_key``. Just in-case any part of
            # ``ResultSet`` peeks through, since much of the
            # original underlying implementation is based on this key.
            'last_key': None,
            'unprocessed_keys': unprocessed_keys,
        }
开发者ID:YongMan,项目名称:boto,代码行数:53,代码来源:table.py

示例6: _scan

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def _scan(self, limit=None, exclusive_start_key=None, segment=None,
              total_segments=None, attributes=None, **filter_kwargs):
        """
        The internal method that performs the actual scan. Used extensively
        by ``ResultSet`` to perform each (paginated) request.
        """
        kwargs = {
            'limit': limit,
            'segment': segment,
            'total_segments': total_segments,
            'attributes_to_get': attributes,
        }

        if exclusive_start_key:
            kwargs['exclusive_start_key'] = {}

            for key, value in exclusive_start_key.items():
                kwargs['exclusive_start_key'][key] = \
                    self._dynamizer.encode(value)

        # Convert the filters into something we can actually use.
        kwargs['scan_filter'] = self._build_filters(
            filter_kwargs,
            using=FILTER_OPERATORS
        )

        raw_results = self.connection.scan(
            self.table_name,
            **kwargs
        )
        results = []
        last_key = None

        for raw_item in raw_results.get('Items', []):
            item = Item(self)
            item.load({
                'Item': raw_item,
            })
            results.append(item)

        if raw_results.get('LastEvaluatedKey', None):
            last_key = {}

            for key, value in raw_results['LastEvaluatedKey'].items():
                last_key[key] = self._dynamizer.decode(value)

        return {
            'results': results,
            'last_key': last_key,
        }
开发者ID:B-Rich,项目名称:boto,代码行数:52,代码来源:table.py

示例7: flush

# 需要导入模块: from boto.dynamodb2.items import Item [as 别名]
# 或者: from boto.dynamodb2.items.Item import load [as 别名]
    def flush(self):
        batch_data = {
            self.table.table_name: [
                # We'll insert data here shortly.
            ],
        }

        for put in self._to_put:
            item = Item(self.table, data=put)
            batch_data[self.table.table_name].append({
                'PutRequest': {
                    'Item': item.prepare_full(),
                }
            })

        for delete in self._to_delete:
            batch_data[self.table.table_name].append({
                'DeleteRequest': {
                    'Key': self.table._encode_keys(delete),
                }
            })
            
        
        response = self.table.connection.batch_write_item(batch_data)
        self._to_put = []
        self._to_delete = []
        
        # handle unprocessed items
        unprocessed = response.get('UnprocessedItems', None)
        if unprocessed:
            unprocessed_list = unprocessed[self.table.table_name]
            item = Item(self)
            for u in unprocessed_list:
                if u.has_key("PutRequest"):
                    item.load({
                        'Item': u['PutRequest']['Item'],
                    })
                    self._to_put.append(item._data)
                elif u.has_key("DeleteRequest"):
                    item.load({
                        'Item': u['DeleteRequest']['Key'],
                    })
                    self._to_delete.append(item._data)
                else:
                    raise Exception("Error respond")
        return True
开发者ID:MingChenSlot,项目名称:SelfScalingBenchmarkForDynamoDB,代码行数:48,代码来源:BatchTable.py


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