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


PHP DynamoDbClient::updateItem方法代码示例

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


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

示例1: processMessage

    /**
     * Processes message from SQS Queue
     * @param QueueMessage $message
     */
    private function processMessage(QueueMessage $message)
    {
        $body = \Keboola\Utils\objectToArray($message->getBody());
        if (isset($body['container_id'], $body['container_name'], $body['container_stats'])) {
            $containerName = $body['container_name'];
            $jobIdAndRunId = $this->getJobIdAndRunIdFromContainerName($containerName);
            if (!empty($jobIdAndRunId)) {
                $containerStats = $body['container_stats'];
                $networkRxBytes = strval(isset($containerStats['network']['rx_bytes']) ? $containerStats['network']['rx_bytes'] : 0);
                $networkTxBytes = strval(isset($containerStats['network']['tx_bytes']) ? $containerStats['network']['tx_bytes'] : 0);
                $updateExpression = 'SET dockerNetwork = :dockerNetwork';
                $expressionAttributeValues = [':dockerNetwork' => ['M' => ['rxBytes' => ['N' => $networkRxBytes], 'txBytes' => ['N' => $networkTxBytes]]], ':newRxBytes' => ['N' => $networkRxBytes], ':newTxBytes' => ['N' => $networkTxBytes]];
                $updateExpression .= ', syrupJobId = if_not_exists(syrupJobId, :syrupJobId)';
                $expressionAttributeValues[':syrupJobId'] = ['S' => $jobIdAndRunId['jobId']];
                $params = ['TableName' => $this->tableName, 'Key' => ['runId' => ['S' => $jobIdAndRunId['runId']]], 'UpdateExpression' => $updateExpression, 'ConditionExpression' => <<<EXPR
attribute_not_exists(dockerNetwork)
or (dockerNetwork.rxBytes < :newRxBytes or dockerNetwork.txBytes < :newTxBytes)
EXPR
, 'ExpressionAttributeValues' => $expressionAttributeValues, 'ReturnValues' => 'UPDATED_NEW'];
                try {
                    $this->dynamoDbClient->updateItem($params);
                } catch (DynamoDbException $e) {
                    if (strpos($e->getMessage(), 'ConditionalCheckFailedException') === false) {
                        throw $e;
                    }
                }
            }
        }
    }
开发者ID:keboola,项目名称:syrup-queue,代码行数:33,代码来源:MetricsProcessContainerStatsCommand.php

示例2: update

 /**
  * {@inheritDoc}
  */
 public function update($storageName, $key, array $data)
 {
     $this->prepareData($key, $data);
     unset($data['id']);
     foreach ($data as $k => $v) {
         $data[$k] = ['Value' => $this->client->formatValue($v)];
     }
     $result = $this->client->updateItem(['TableName' => $storageName, 'Key' => ['id' => ['S' => $key]], 'AttributeUpdates' => $data]);
 }
开发者ID:billschaller,项目名称:KeyValueStore,代码行数:12,代码来源:DynamoDbStorage.php

示例3: update

 /**
  * {@inheritDoc}
  */
 public function update($storageName, $key, array $data)
 {
     $this->prepareData($key, $data);
     unset($data['id']);
     foreach ($data as $k => $v) {
         $data[$k] = array("Value" => $this->client->formatValue($v));
     }
     $result = $this->client->updateItem(array('TableName' => $storageName, 'Key' => array("id" => array('S' => $key)), "AttributeUpdates" => $data));
 }
开发者ID:pkdevbox,项目名称:KeyValueStore,代码行数:12,代码来源:DynamoDbStorage.php

示例4: updateItem

 /**
  * updateItem
  *
  * @param array $values associative array
  *
  * $values = array(
  *     'name' => 'John',
  *     'age'  => 30,
  * );
  *
  * @param array $options
  *
  * $options = array(
  *     'ReturnValues'                => 'string',
  *     'ReturnConsumedCapacity'      => 'string',
  *     'ReturnItemCollectionMetrics' => 'string',
  *     'Action'                      => array('age' => 'ADD'),
  *     'Exists'                      => array('age' => true),
  * );
  *
  * @param array $expected
  *
  * @return \Guzzle\Service\Resource\Model
  *
  * @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_updateItem
  */
 public function updateItem(array $values, array $options = array(), array $expected = array())
 {
     $conditions = $this->_getKeyConditions();
     $action = array();
     // Update Action (ADD|PUT|DELETE)
     if (isset($options['Action'])) {
         $action = $options['Action'];
     }
     $attributes = $this->_formatAttributeUpdates($values, $action);
     foreach ($conditions as $key => $value) {
         if (isset($attributes[$key])) {
             unset($attributes[$key]);
         }
     }
     $args = array('TableName' => $this->_table_name, 'Key' => $conditions, 'AttributeUpdates' => $attributes, 'ReturnValues' => 'ALL_NEW', 'ReturnConsumedCapacity' => 'TOTAL', 'ReturnItemCollectionMetrics' => 'SIZE');
     // Set Expected if exists
     if ($expected || isset($options['Exists'])) {
         $exists = isset($options['Exists']) ? $options['Exists'] : array();
         $args['Expected'] = $this->_formatAttributeExpected($expected, $exists);
     }
     // Merge $options to $args
     $option_names = array('ReturnValues', 'ReturnConsumedCapacity', 'ReturnItemCollectionMetrics');
     foreach ($option_names as $option_name) {
         if (isset($options[$option_name])) {
             $args[$option_name] = $options[$option_name];
         }
     }
     $item = self::$_client->updateItem($args);
     self::_logQuery('updateItem', $args, $item);
     return $item;
 }
开发者ID:albertleao,项目名称:kettle,代码行数:57,代码来源:kettle.php

示例5: update

 /**
  * Update an item via the update_item call
  * @param string $table The item table
  * @param mixed $hash The primary hash key
  * @param mixed|null $range The primary range key
  * @param AttributeUpdate $update
  * @param Context\Update|null $context The call context
  * @return array|null
  * @throws Exception\AttributesException
  */
 public function update($table, $hash, $range = null, AttributeUpdate $update, Context\Update $context = null)
 {
     if (null !== $this->logger) {
         $this->log('Update on table' . $table);
     }
     // Primary key
     $hash = new Attribute($hash);
     $key = array('HashKeyElement' => $hash->getForDynamoDB());
     // Range key
     if (null !== $range) {
         $range = new Attribute($range);
         $key['RangeKeyElement'] = $range->getForDynamoDB();
     }
     $attributes = array();
     foreach ($update as $name => $attribute) {
         /** @var $attribute Attribute */
         $attributes[$name] = $attribute->getForDynamoDB();
     }
     $parameters = array('TableName' => $table, 'Key' => $key, 'AttributeUpdates' => $attributes);
     if (null !== $context) {
         $parameters += $context->getForDynamoDB();
     }
     if (null !== $this->logger) {
         $this->log('Update request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
     }
     $response = $this->connector->updateItem($parameters);
     if (null !== $this->logger) {
         $this->log('Update request response : ' . print_r($response, true), Logger::DEBUG);
     }
     // Update write counter
     $this->addConsumedWriteUnits($table, floatval($response['ConsumedCapacityUnits']));
     return $this->populateAttributes($response);
 }
开发者ID:16hands,项目名称:riverline-dynamodb,代码行数:43,代码来源:Connection.php

示例6: markDocumentAsProcessed

    /**
     * Marks specified document as processed, since it doesn't have job
     * @param $runId
     */
    private function markDocumentAsProcessed($runId)
    {
        $updateExpression = <<<EXPR
SET hasSyrupJob = :hasSyrupJob
EXPR;
        $expressionAttributeValues = [':hasSyrupJob' => ['N' => strval(0)]];
        $params = ['TableName' => $this->tableName, 'Key' => ['runId' => ['S' => strval($runId)]], 'UpdateExpression' => $updateExpression, 'ExpressionAttributeValues' => $expressionAttributeValues, 'ReturnValues' => 'UPDATED_NEW'];
        $this->dynamoDbClient->updateItem($params);
    }
开发者ID:keboola,项目名称:syrup-queue,代码行数:13,代码来源:MetricsProcessElasticStatsCommand.php

示例7: updateItem

 /**
  * Edits an existing item's attributes, or inserts a new item if it does not already exist.
  * You can put, delete, or add attribute values.
  * You can also perform a conditional update (insert a new attribute name-value pair if it doesn't exist, or replace an existing name-value pair if it has certain expected attribute values).
  *
  * @param string $tableName                   The name of the table containing the item to update.
  * @param array  $key                         Associative array of <AttributeName> keys mapping to (associative-array) values.
  * @param array  $attributeUpdates            The names of attributes to be modified, the action to perform on each, and the new value for each.
  * @param array  $expected                    A map of attribute/condition pairs. This is the conditional block for the UpdateItem operation. All the conditions must be met for the operation to succeed.
  * @param string $conditionnalOperator        Operator between each condition of $expected argument.
  * @param string $returnValues                Use ReturnValues if you want to get the item attributes as they appeared either before or after they were updated.
  * @param string $returnConsumedCapacity      Sets consumed capacity return mode.
  * @param string $returnItemCollectionMetrics If set to SIZE, statistics about item collections, if any, that were modified during the operation are returned in the response.
  *
  * @return Guzzle\Service\Resource\Model
  *
  * @see http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_updateItem
  */
 public function updateItem($tableName, array $key, array $attributeUpdates = null, array $expected = null, $conditionnalOperator = self::COND_AND, $returnValues = self::RETURN_NONE, $returnConsumedCapacity = self::CAPACITY_NONE, $returnItemCollectionMetrics = self::METRICS_NONE)
 {
     $args = ['TableName' => $tableName, 'Key' => $key, 'ConditionnalOperator' => $conditionnalOperator, 'ReturnValues' => $returnValues, 'ReturnConsumedCapacity' => $returnConsumedCapacity, 'ReturnItemCollectionMetrics' => $returnItemCollectionMetrics];
     if ($attributeUpdates !== null) {
         $args['AttributeUpdates'] = $attributeUpdates;
     }
     if ($expected !== null) {
         $args['Expected'] = $expected;
     }
     return $this->client->updateItem($args);
 }
开发者ID:m6web,项目名称:aws-bundle,代码行数:29,代码来源:Client.php

示例8: hSet

 /**
  * Sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. <br />
  * If field already exists in the hash, it is overwritten. <br />
  * @param string $key The key at which to set a hash
  * @param string $field The field to set a value to
  * @param mixed $value The value to be set
  * @return integer Returns 1 if field is a new field in the hash and value was set, 0 if field already exists in the hash and the value was updated
  */
 public function hSet($key, $field, $value)
 {
     if (!($key !== '') || !($field !== '')) {
         return false;
     }
     try {
         $result = $this->client->updateItem(array('TableName' => $this->tableName, 'Key' => array(self::SIMPLE_KEY_NAME => array('S' => $key)), 'AttributeUpdates' => array(self::HPREFIX . $field => array('Action' => 'PUT', 'Value' => array('B' => $value)))));
         return true;
     } catch (\Exception $ex) {
         return false;
     }
 }
开发者ID:oat-sa,项目名称:lib-advkv-dynamodb,代码行数:20,代码来源:DynamoDbDriver.php

示例9: updateStorageStats

    /**
     * Updates/increments storage stats
     * @param $body
     */
    private function updateStorageStats($body)
    {
        $storageMetrics = $this->prepareStorageStats($body);
        $updateExpression = <<<EXPR
SET sapiStorage.inBytes = sapiStorage.inBytes + :inBytes,
sapiStorage.inBytesUncompressed = sapiStorage.inBytesUncompressed + :inBytesUncompressed,
sapiStorage.outBytes = sapiStorage.outBytes + :outBytes,
sapiStorage.outBytesUncompressed = sapiStorage.outBytesUncompressed + :outBytesUncompressed,
sapiStorage.inBytesComputed = sapiStorage.inBytesComputed + :inBytesComputed,
sapiStorage.outBytesComputed = sapiStorage.outBytesComputed + :outBytesComputed
EXPR;
        $expressionAttributeValues = [':inBytes' => ['N' => $storageMetrics['inBytes']], ':inBytesUncompressed' => ['N' => $storageMetrics['inBytesUncompressed']], ':outBytes' => ['N' => $storageMetrics['outBytes']], ':outBytesUncompressed' => ['N' => $storageMetrics['outBytesUncompressed']], ':inBytesComputed' => ['N' => $storageMetrics['inBytesUncompressed'] != 0 ? $storageMetrics['inBytesUncompressed'] : $storageMetrics['inBytes']], ':outBytesComputed' => ['N' => $storageMetrics['outBytesUncompressed'] != 0 ? $storageMetrics['outBytesUncompressed'] : $storageMetrics['outBytes']]];
        $params = ['TableName' => $this->tableName, 'Key' => ['runId' => ['S' => $body['runId']]], 'UpdateExpression' => $updateExpression, 'ExpressionAttributeValues' => $expressionAttributeValues, 'ReturnValues' => 'UPDATED_NEW'];
        try {
            $this->dynamoDbClient->updateItem($params);
        } catch (DynamoDbException $e) {
            if (strpos($e->getMessage(), 'ConditionalCheckFailedException') === false) {
                throw $e;
            }
        }
    }
开发者ID:keboola,项目名称:syrup-queue,代码行数:25,代码来源:MetricsProcessStorageStatsCommand.php


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