예제 #1
0
파일: item.py 프로젝트: djacobs/boto
 def dynamize(self):
     d = {self.hash_key_name: dynamize_value(self.hash_key)}
     if self.range_key:
         d[self.range_key_name] = dynamize_value(self.range_key)
     for attr_name in self.attrs:
         d[attr_name] = dynamize_value(self.attrs[attr_name])
     return d
예제 #2
0
파일: table.py 프로젝트: djacobs/boto
    def query(self, hash_key, range_key_condition=None,
              attributes_to_get=None, limit=None, consistent_read=False,
              scan_index_forward=True, exclusive_start_key=None):
        """
        Perform a query on the table.
        
        :type hash_key: int|long|float|str|unicode
        :param hash_key: The HashKey of the requested item.  The
            type of the value must match the type defined in the
            schema for the table.

        :type range_key_condition: dict
        :param range_key_condition: A dict where the key is either
            a scalar value appropriate for the RangeKey in the schema
            of the database or a tuple of such values.  The value 
            associated with this key in the dict will be one of the
            following conditions:

            'EQ'|'LE'|'LT'|'GE'|'GT'|'BEGINS_WITH'|'BETWEEN'

            The only condition which expects or will accept a tuple
            of values is 'BETWEEN', otherwise a scalar value should
            be used as the key in the dict.
        
        :type attributes_to_get: list
        :param attributes_to_get: A list of attribute names.
            If supplied, only the specified attribute names will
            be returned.  Otherwise, all attributes will be returned.

        :type limit: int
        :param limit: The maximum number of items to return.

        :type consistent_read: bool
        :param consistent_read: If True, a consistent read
            request is issued.  Otherwise, an eventually consistent
            request is issued.

        :type scan_index_forward: bool
        :param scan_index_forward: Specified forward or backward
            traversal of the index.  Default is forward (True).

        :type exclusive_start_key: list or tuple
        :param exclusive_start_key: Primary key of the item from
            which to continue an earlier query.  This would be
            provided as the LastEvaluatedKey in that query.
        """
        rkc = self.dynamize_range_key_condition(range_key_condition)
        response = self.layer1.query(self.name, dynamize_value(hash_key),
                                     rkc, attributes_to_get, limit,
                                     consistent_read, scan_index_forward,
                                     exclusive_start_key,
                                     object_hook=item_object_hook)
        items = []
        for item in response['Items']:
            hash_key = item[self.schema.hash_key_name]
            range_key = item[self.schema.range_key_name]
            items.append(Item(self, hash_key, range_key, item))
        return items
예제 #3
0
파일: item.py 프로젝트: numan/boto
 def dynamize_expected_value(self, expected_value):
     """
     Convert an expected_value parameter into the data structure
     required for Layer1.
     """
     d = None
     if expected_value:
         d = {}
         for attr_name in expected_value:
             d[attr_name] = dynamize_value(expected_value[attr_name])
     return d
예제 #4
0
파일: table.py 프로젝트: djacobs/boto
 def dynamize_range_key_condition(self, range_key_condition):
     """
     Convert a range_key_condition parameter into the
     structure required by Layer1.
     """
     d = None
     if range_key_condition:
         d = {}
         for range_value in range_key_condition:
             range_condition = range_key_condition[range_value]
             if range_condition == 'BETWEEN':
                 if isinstance(range_value, tuple):
                     avl = [dynamize_value(v) for v in range_value]
                 else:
                     msg = 'BETWEEN condition requires a tuple value'
                     raise TypeError(msg)
             elif isinstance(range_value, tuple):
                 msg = 'Tuple can only be supplied with BETWEEN condition'
                 raise TypeError(msg)
             else:
                 avl = [dynamize_value(range_value)]
         d['RangeKeyCondition'] = {'AttributeValueList': avl,
                                   'ComparisonOperator': range_condition}
     return d
예제 #5
0
파일: item.py 프로젝트: djacobs/boto
 def dynamize_expected_value(self, expected_value):
     """
     Convert an expected_value parameter into the data structure
     required for Layer1.
     """
     d = None
     if expected_value:
         d = {}
         for attr_name in expected_value:
             attr_value = expected_value[attr_name]
             if attr_value is True:
                 attr_value = {'Exists': True}
             elif attr_value is False:
                 attr_value = {'Exists': False}
             else:
                 attr_value = dynamize_value(expected_value[attr_name])
             d[attr_name] = attr_value
     return d