src/Resources/DynamoDbTable.php
protected function commitTransaction($extras = null)
    {
        if (empty($this->batchRecords) && empty($this->batchIds)) {
            return null;
        }

//        $ssFilters = array_get( $extras, 'ss_filters' );
        $fields = array_get($extras, ApiOptions::FIELDS);
        $requireMore = array_get($extras, 'require_more');
        $idFields = array_get($extras, 'id_fields');

        $out = [];
        switch ($this->getAction()) {
            case Verbs::POST:
                $requests = [];
                foreach ($this->batchRecords as $item) {
                    $requests[] = ['PutRequest' => ['Item' => $item]];
                }

                /*$result = */
                $this->getConnection()->batchWriteItem(
                    ['RequestItems' => [$this->transactionTable => $requests]]
                );

                // todo check $result['UnprocessedItems'] for 'PutRequest'

                foreach ($this->batchRecords as $item) {
                    $out[] = static::cleanRecord($this->unformatAttributes($item), $fields, $idFields);
                }
                break;

            case Verbs::PUT:
                $requests = [];
                foreach ($this->batchRecords as $item) {
                    $requests[] = ['PutRequest' => ['Item' => $item]];
                }

                /*$result = */
                $this->getConnection()->batchWriteItem(
                    ['RequestItems' => [$this->transactionTable => $requests]]
                );

                // todo check $result['UnprocessedItems'] for 'PutRequest'

                foreach ($this->batchRecords as $item) {
                    $out[] = static::cleanRecord($this->unformatAttributes($item), $fields, $idFields);
                }
                break;

            case Verbs::PATCH:
                throw new BadRequestException('Batch operation not supported for patch.');
                break;

            case Verbs::DELETE:
                $requests = [];
                foreach ($this->batchIds as $id) {
                    $record = [$idFields[0] => $id];
                    $out[] = $record;
                    $key = static::buildKey($this->tableIdsInfo, $record);
                    $requests[] = ['DeleteRequest' => ['Key' => $key]];
                }
                if ($requireMore) {
                    $scanProperties = [
                        'Keys'           => $this->batchRecords,
                        'ConsistentRead' => true,
                    ];

                    $attributes = static::buildProjectionExpression($fields, $idFields);
                    if (!empty($attributes)) {
                        $scanProperties['ProjectionExpression'] = $attributes;
                    }

                    // Get multiple items by key in a BatchGetItem request
                    $result = $this->getConnection()->batchGetItem(
                        [
                            'RequestItems' => [
                                $this->transactionTable => $scanProperties
                            ]
                        ]
                    );

                    $out = [];
                    $items = $result->search(str_replace('/', '.', "Responses/{$this->transactionTable}"));
                    foreach ($items as $item) {
                        $out[] = $this->unformatAttributes($item);
                    }
                }

                /*$result = */
                $this->getConnection()->batchWriteItem(
                    ['RequestItems' => [$this->transactionTable => $requests]]
                );

                // todo check $result['UnprocessedItems'] for 'DeleteRequest'
                break;

            case Verbs::GET:
                $keys = [];
                foreach ($this->batchIds as $id) {
                    $record = [$idFields[0] => $id];
                    $key = static::buildKey($this->tableIdsInfo, $record);
                    $keys[] = $key;
                }

                $scanProperties = [
                    'Keys'           => $keys,
                    'ConsistentRead' => true,
                ];

                $fields = static::buildProjectionExpression($fields, $idFields);
                if (!empty($fields)) {
                    $scanProperties['ProjectionExpression'] = $fields;
                }

                // Get multiple items by key in a BatchGetItem request
                $result = $this->getConnection()->batchGetItem(
                    [
                        'RequestItems' => [
                            $this->transactionTable => $scanProperties
                        ]
                    ]
                );

                $items = $result->search(str_replace('/', '.', "Responses/{$this->transactionTable}"));
                foreach ($items as $item) {
                    $out[] = $this->unformatAttributes($item);
                }
                break;
            default:
                break;
        }

        $this->batchIds = [];
        $this->batchRecords = [];

        return $out;
    }
protected function commitTransaction($extras = null)
    {
        if (empty($this->batchRecords) && empty($this->batchIds)) {
            return null;
        }

//        $ssFilters = array_get( $extras, 'ss_filters' );
        $fields = array_get($extras, ApiOptions::FIELDS);
        $requireMore = array_get($extras, 'require_more');
        $idFields = array_get($extras, 'id_fields');

        $out = [];
        switch ($this->getAction()) {
            case Verbs::POST:
                $requests = [];
                foreach ($this->batchRecords as $item) {
                    $requests[] = ['PutRequest' => ['Item' => $item]];
                }

                /*$result = */
                $this->getConnection()->batchWriteItem(
                    ['RequestItems' => [$this->transactionTable => $requests]]
                );

                // todo check $result['UnprocessedItems'] for 'PutRequest'

                foreach ($this->batchRecords as $item) {
                    $out[] = static::cleanRecord($this->unformatAttributes($item), $fields, $idFields);
                }
                break;

            case Verbs::PUT:
                $requests = [];
                foreach ($this->batchRecords as $item) {
                    $requests[] = ['PutRequest' => ['Item' => $item]];
                }

                /*$result = */
                $this->getConnection()->batchWriteItem(
                    ['RequestItems' => [$this->transactionTable => $requests]]
                );

                // todo check $result['UnprocessedItems'] for 'PutRequest'

                foreach ($this->batchRecords as $item) {
                    $out[] = static::cleanRecord($this->unformatAttributes($item), $fields, $idFields);
                }
                break;

            case Verbs::PATCH:
                throw new BadRequestException('Batch operation not supported for patch.');
                break;

            case Verbs::DELETE:
                $requests = [];
                foreach ($this->batchIds as $id) {
                    $record = [$idFields[0] => $id];
                    $out[] = $record;
                    $key = static::buildKey($this->tableIdsInfo, $record);
                    $requests[] = ['DeleteRequest' => ['Key' => $key]];
                }
                if ($requireMore) {
                    $scanProperties = [
                        'Keys'           => $this->batchRecords,
                        'ConsistentRead' => true,
                    ];

                    $attributes = static::buildProjectionExpression($fields, $idFields);
                    if (!empty($attributes)) {
                        $scanProperties['ProjectionExpression'] = $attributes;
                    }

                    // Get multiple items by key in a BatchGetItem request
                    $result = $this->getConnection()->batchGetItem(
                        [
                            'RequestItems' => [
                                $this->transactionTable => $scanProperties
                            ]
                        ]
                    );

                    $out = [];
                    $items = $result->search(str_replace('/', '.', "Responses/{$this->transactionTable}"));
                    foreach ($items as $item) {
                        $out[] = $this->unformatAttributes($item);
                    }
                }

                /*$result = */
                $this->getConnection()->batchWriteItem(
                    ['RequestItems' => [$this->transactionTable => $requests]]
                );

                // todo check $result['UnprocessedItems'] for 'DeleteRequest'
                break;

            case Verbs::GET:
                $keys = [];
                foreach ($this->batchIds as $id) {
                    $record = [$idFields[0] => $id];
                    $key = static::buildKey($this->tableIdsInfo, $record);
                    $keys[] = $key;
                }

                $scanProperties = [
                    'Keys'           => $keys,
                    'ConsistentRead' => true,
                ];

                $fields = static::buildProjectionExpression($fields, $idFields);
                if (!empty($fields)) {
                    $scanProperties['ProjectionExpression'] = $fields;
                }

                // Get multiple items by key in a BatchGetItem request
                $result = $this->getConnection()->batchGetItem(
                    [
                        'RequestItems' => [
                            $this->transactionTable => $scanProperties
                        ]
                    ]
                );

                $items = $result->search(str_replace('/', '.', "Responses/{$this->transactionTable}"));
                foreach ($items as $item) {
                    $out[] = $this->unformatAttributes($item);
                }
                break;
            default:
                break;
        }

        $this->batchIds = [];
        $this->batchRecords = [];

        return $out;
    }
{@inheritdoc}