예제 #1
0
파일: db.py 프로젝트: pombredanne/ddbmock
    def get_batch(self, batch):
        """
        Batch processor. Dispatches call to appropriate :py:class:`ddbmock.database.table.Table`
        methods. This is the only low_level API that directly pushes throughput usage.

        :param batch: raw DynamoDB request batch.

        :returns: dict compatible with DynamoDB API

        :raises: :py:exc:`ddbmock.errors.ValidationException` if a ``range_key`` was provided while table has none.
        :raises: :py:exc:`ddbmock.errors.ResourceNotFoundException` if a table does not exist.
        """
        ret = defaultdict(dict)

        for tablename, batch in batch.iteritems():
            base_capacity = 1 if batch[u'ConsistentRead'] else 0.5
            fields = batch[u'AttributesToGet']
            table = self.get_table(tablename)
            units = ItemSize(0)
            items = []
            for key in batch[u'Keys']:
                item = table.get(key, fields)
                if item:
                    units += item.get_size().as_units()
                    items.append(item)
            push_read_throughput(tablename, base_capacity*units)
            ret[tablename][u'Items'] = items
            ret[tablename][u'ConsumedCapacityUnits'] = base_capacity*units

        return ret
예제 #2
0
def get_item(post, table):
    base_capacity = 1 if post[u'ConsistentRead'] else 0.5
    item = table.get(post[u'Key'], post[u'AttributesToGet'])

    if item is not None:
        capacity = base_capacity * item.get_size().as_units()
        push_read_throughput(table.name, capacity)
        return {
            "ConsumedCapacityUnits": capacity,
            "Item": item,
        }
    else:
        push_read_throughput(table.name, base_capacity)
        return {
            "ConsumedCapacityUnits": base_capacity,
        }
예제 #3
0
def get_item(post, table):
    base_capacity = 1 if post[u'ConsistentRead'] else 0.5
    item = table.get(post[u'Key'], post[u'AttributesToGet'])

    if item is not None:
        capacity = base_capacity*item.get_size().as_units()
        push_read_throughput(table.name, capacity)
        return {
            "ConsumedCapacityUnits": capacity,
            "Item": item,
        }
    else:
        push_read_throughput(table.name, base_capacity)
        return {
            "ConsumedCapacityUnits": base_capacity,
        }
예제 #4
0
파일: db.py 프로젝트: dekked/dynamodb-mock
    def get_batch(self, batch):
        ret = defaultdict(dict)

        for tablename, batch in batch.iteritems():
            base_capacity = 1 if batch[u'ConsistentRead'] else 0.5
            fields = batch[u'AttributesToGet']
            table = self.get_table(tablename)
            units = ItemSize(0)
            items = []
            for key in batch[u'Keys']:
                item = table.get(key, fields)
                if item:
                    units += item.get_size().as_units()
                    items.append(item)
            push_read_throughput(tablename, base_capacity*units)
            ret[tablename][u'Items'] = items
            ret[tablename][u'ConsumedCapacityUnits'] = base_capacity*units

        return ret