Exemplo n.º 1
0
 /**
  * @param string $tableName
  * @param array $values
  */
 public function putItems($tableName, $values)
 {
     $unprocessedItems = [];
     foreach ($values as $item) {
         $unprocessedItems[] = ['PutRequest' => ['Item' => Marshaler::marshal($item)]];
     }
     while (!empty($unprocessedItems)) {
         $chunks = array_chunk($unprocessedItems, 25);
         $unprocessedItems = [];
         foreach ($chunks as $chunk) {
             $request = ['RequestItems' => [$tableName => $chunk]];
             $command = $this->getClient()->getCommand('BatchWriteItem', $request);
             $response = $this->getClient()->execute($command);
             if (isset($response->get("UnprocessedItems")[$tableName])) {
                 $unprocessedItems = $unprocessedItems + $response->get("UnprocessedItems")[$tableName];
             }
         }
     }
     return $response;
 }
Exemplo n.º 2
0
 /**
  * @param array $response The raw response result from operation.
  * @return array array of values.
  */
 public function getItemsFromResponse($response)
 {
     if (in_array($this->using, [self::USING_QUERY, self::USING_SCAN])) {
         $rows = array_map(function ($item) {
             return Marshaler::unmarshalItem($item);
         }, $response['Items']);
     } else {
         if ($this->using == self::USING_BATCH_GET_ITEM) {
             $rows = array_map(function ($item) {
                 return Marshaler::unmarshalItem($item);
             }, $response['Responses'][$this->from]);
         } else {
             if ($this->using == self::USING_GET_ITEM) {
                 $row = Marshaler::unmarshalItem($response['Item']);
                 $rows = [$row];
             }
         }
     }
     $storedResponse = self::extractStoredResponseData($this->storeResponseData, $response);
     if (!empty($storedResponse)) {
         $rows = array_map(function ($row) use($storedResponse) {
             $row[self::RESPONSE_KEY_PARAM] = $storedResponse;
             return $row;
         }, $rows);
     }
     return $rows;
 }
Exemplo n.º 3
0
 /**
  * Builds a DynamoDB command to put multiple items.
  *
  * @param string $table   The name of the table to be created.
  * @param array  $values  The value to put into the table.
  * @param array  $options The value to put into the table.
  * @return array The create table request syntax. The first element is the name of the command,
  * the second is the argument.
  */
 public function batchPutItem($table, array $values, array $options = [])
 {
     $name = 'BatchWriteItem';
     $requests = array_map(function ($value) {
         return ['PutRequest' => ['Item' => Marshaler::marshalItem($value)]];
     }, $values);
     $argument = array_merge(['RequestItems' => [$table => $requests]], $options);
     return [$name, $argument];
 }
Exemplo n.º 4
0
 /**
  * Creates a condition based on column-value pairs.
  * @param array $condition the condition specification.
  * @param array $params the binding parameters to be populated
  * @return string the generated SQL expression
  */
 public function buildHashCondition($condition, Query &$query)
 {
     $parts = [];
     foreach ($condition as $column => $value) {
         if (is_array($value) || $value instanceof Query) {
             // IN condition
             $parts[] = $this->buildInCondition('IN', [$column, $value], $query);
         } else {
             $varname = self::PARAM_PREFIX . count($query->expressionAttributesValues);
             $query->expressionAttributesValues[$varname] = Marshaler::marshal($value);
             $parts[] = "{$column}={$varname}";
         }
     }
     return count($parts) === 1 ? $parts[0] : '(' . implode(') AND (', $parts) . ')';
 }