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


PHP DynamoDbClient::putItem方法代码示例

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


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

示例1: saveData

 /**
  * Save marshaled data
  *
  * @param $id
  * @param $data
  * @return bool|\Guzzle\Service\Resource\Model
  */
 public function saveData($id, $data)
 {
     if (empty($this->table)) {
         return false;
     }
     $client_data = ['TableName' => $this->table, 'Item' => ['id' => ['S' => $id], 'item_status' => ['S' => 'entered'], 'payload' => ['M' => $this->marshallData($data)], 'date' => ['S' => utf8_encode((string) date('Y-m-d H:i:s'))]]];
     $result = $this->client->putItem($client_data);
     return $result;
 }
开发者ID:kameshwariv,项目名称:testexample,代码行数:16,代码来源:Ddb.php

示例2: write

 /**
  * {@inheritdoc}
  */
 protected function write(array $record)
 {
     $filtered = $this->filterEmptyFields($record['formatted']);
     if ($this->version === 3) {
         $formatted = $this->marshaler->marshalItem($filtered);
     } else {
         $formatted = $this->client->formatAttributes($filtered);
     }
     $this->client->putItem(['TableName' => $this->table, 'Item' => $formatted]);
 }
开发者ID:earncef,项目名称:monolog,代码行数:13,代码来源:DynamoDbHandler.php

示例3: saved

 public function saved($model)
 {
     $attrs = $model->attributesToArray();
     // $this->attributeFilter->filter($attrs);
     try {
         $this->dynamoDbClient->putItem(['TableName' => $model->getDynamoDbTableName(), 'Item' => $this->marshaler->marshalItem($attrs)]);
     } catch (Exception $e) {
         Log::info($e);
     }
 }
开发者ID:warrick-loyaltycorp,项目名称:laravel-dynamodb,代码行数:10,代码来源:ModelObserver.php

示例4: testPutItem

 public function testPutItem()
 {
     try {
         $item = $this->marshaler->marshal($this->message);
         self::$client->putItem(['TableName' => self::$tableName, 'Item' => $item]);
     } catch (\Exception $e) {
         $this->fail($e->getMessage());
         return;
     }
 }
开发者ID:gdbots,项目名称:pbj-php,代码行数:10,代码来源:DynamoDbTest.php

示例5: save

 public function save(array $options = [])
 {
     if (!$this->getKey()) {
         $this->fireModelEvent('creating');
     }
     // $this->attributeFilter->filter($this->attributes);
     try {
         $this->client->putItem(['TableName' => $this->getTable(), 'Item' => $this->marshalItem($this->attributes)]);
         return true;
     } catch (Exception $e) {
         Log::info($e);
         return false;
     }
 }
开发者ID:warrick-loyaltycorp,项目名称:laravel-dynamodb,代码行数:14,代码来源:DynamoDbModel.php

示例6: put

 /**
  * Add an item to DynamoDB via the put_item call
  * @param Item $item
  * @param Context\Put|null $context The call context
  * @return array|null
  * @throws Exception\AttributesException
  */
 public function put(Item $item, Context\Put $context = null)
 {
     $table = $item->getTable();
     if (null !== $this->logger) {
         $this->log('Put on table ' . $table);
     }
     if (empty($table)) {
         throw new \Riverline\DynamoDB\Exception\AttributesException('Item do not have table defined');
     }
     $attributes = array();
     foreach ($item as $name => $attribute) {
         /** @var $attribute \Riverline\DynamoDB\Attribute */
         if ("" !== $attribute->getValue()) {
             // Only not empty string
             $attributes[$name] = $attribute->getForDynamoDB();
         }
     }
     $parameters = array('TableName' => $table, 'Item' => $attributes);
     if (null !== $context) {
         $parameters += $context->getForDynamoDB();
     }
     if (null !== $this->logger) {
         $this->log('Put request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
     }
     $response = $this->connector->putItem($parameters);
     if (null !== $this->logger) {
         $this->log('Put 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,代码行数:39,代码来源:Connection.php

示例7: seed

 protected function seed($attributes = [])
 {
     $item = ['id' => ['S' => str_random(36)], 'name' => ['S' => str_random(36)], 'description' => ['S' => str_random(256)], 'count' => ['N' => rand()]];
     $item = array_merge($item, $attributes);
     $this->dynamoDbClient->putItem(['TableName' => $this->testModel->getTable(), 'Item' => $item]);
     return $item;
 }
开发者ID:warrick-loyaltycorp,项目名称:laravel-dynamodb,代码行数:7,代码来源:DynamoDbModelTest.php

示例8: testIteratesOverScan

 /**
  * @depends testCreatesTable
  */
 public function testIteratesOverScan()
 {
     self::log('Adding 3 items to the table');
     $this->client->putItem(array('TableName' => $this->table, 'Item' => Item::fromArray(array('foo' => 'Bar', 'bar' => 10))));
     self::log('Added 1 item');
     $this->client->putItem(array('TableName' => $this->table, 'Item' => Item::fromArray(array('foo' => 'Bar', 'bar' => 20))));
     self::log('Added 2 items');
     $this->client->putItem(array('TableName' => $this->table, 'Item' => Item::fromArray(array('foo' => 'Bar', 'bar' => 30))));
     self::log('Added 3 items');
     self::log('Waiting until at least 3 items are in the table');
     $client = $this->client;
     $table = $this->table;
     $waiter = new CallableWaiter();
     $waiter->setCallable(function () use($client, $table) {
         $result = $client->scan(array('TableName' => $table));
         return count($result['Items']) >= 3;
     })->setMaxAttempts(10)->setInterval(1);
     $iterator = $client->getIterator('Scan', array('TableName' => $this->table, 'Limit' => 2, 'ScanFilter' => array('bar' => array('AttributeValueList' => array(array('N' => '5')), 'ComparisonOperator' => 'GT'))));
     $items = $iterator->toArray();
     $this->assertTrue(count($items) >= 3, 'Expected 3 items, got ' . count($items));
     $this->assertTrue($iterator->getRequestCount() >= 2);
     $mustMatch = $this->rangeKeyValues;
     foreach ($items as $item) {
         if (false !== ($pos = array_search($item['bar']['N'], $mustMatch))) {
             unset($mustMatch[$pos]);
             if (empty($mustMatch)) {
                 break;
             }
         }
     }
     if (!empty($mustMatch)) {
         $this->fail('All known items were not found in scan: ' . var_export($mustMatch, true) . ' - found: ' . var_export($items, true));
     }
     return $mustMatch;
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:38,代码来源:IntegrationTest.php

示例9: fillTable

 /**
  * Fill the table with data
  */
 protected static function fillTable()
 {
     $data = ['key' => 'dev', 'settings' => self::getTestData()];
     $marshaler = new Marshaler();
     $item = $marshaler->marshalItem($data);
     self::$dynamodb->putItem(['TableName' => self::TABLE_NAME, 'Item' => $item]);
 }
开发者ID:sven4ask,项目名称:config,代码行数:10,代码来源:DynamoDBLoaderTest.php

示例10: set

 public function set(array $obj, $checkAndSet = false, &$casValue = null)
 {
     $requestArgs = ["TableName" => $this->tableName];
     if ($this->casField) {
         $old_cas = isset($obj[$this->casField]) ? $obj[$this->casField] : null;
         $casValue = time();
         $obj[$this->casField] = $casValue;
         if ($checkAndSet) {
             if ($old_cas) {
                 $requestArgs['ConditionExpression'] = "#CAS = :cas_val";
                 $requestArgs['ExpressionAttributeNames'] = ["#CAS" => $this->casField];
                 $requestArgs['ExpressionAttributeValues'] = [":cas_val" => ["N" => strval(intval($old_cas))]];
             } else {
                 $requestArgs['ConditionExpression'] = "attribute_not_exists(#CAS)";
                 $requestArgs['ExpressionAttributeNames'] = ["#CAS" => $this->casField];
             }
         }
     }
     $item = DynamoDbItem::createFromArray($obj, $this->attributeTypes);
     $requestArgs['Item'] = $item->getData();
     try {
         $this->dbClient->putItem($requestArgs);
     } catch (DynamoDbException $e) {
         if ($e->getAwsErrorCode() == "ConditionalCheckFailedException") {
             return false;
         }
         mtrace($e, "Exception while setting dynamo db item, aws code = " . $e->getAwsErrorCode() . ", type = " . $e->getAwsErrorType());
         throw $e;
     }
     return true;
 }
开发者ID:oasmobile,项目名称:php-aws-wrappers,代码行数:31,代码来源:DynamoDbTable.php

示例11: update

 /**
  * {@inheritDoc}
  *
  * @throws \Aws\DynamoDb\Exception\DynamoDBException
  */
 public function update(EntityInterface $entity, array $commandOptions = array())
 {
     $this->dispatchEntityRequestEvent(Events::ENTITY_PRE_UPDATE, $entity);
     $commandOptions += $this->formatPutItemCommandOptions($entity, true);
     $model = $this->dynamoDb->putItem($commandOptions);
     $this->dispatchEntityResponseEvent(Events::ENTITY_POST_UPDATE, $entity, $model);
     return true;
 }
开发者ID:cpliakas,项目名称:dynamo-db-odm,代码行数:13,代码来源:DocumentManager.php

示例12: putItem

 /**
  * Creates a new item, or replaces an old item with a new item.
  *
  * @param string $tableName                   The name of the table to contain the item.
  * @param array  $item                        Associative array of <AttributeName> keys mapping to (associative-array) values.
  * @param array  $expected                    This is the conditional block for the PutItem 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 before 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#_putItem
  */
 public function putItem($tableName, array $item, array $expected = null, $conditionnalOperator = self::COND_AND, $returnValues = self::RETURN_NONE, $returnConsumedCapacity = self::CAPACITY_NONE, $returnItemCollectionMetrics = self::METRICS_NONE)
 {
     $args = ['TableName' => $tableName, 'Item' => $item, 'ConditionnalOperator' => $conditionnalOperator, 'ReturnValues' => $returnValues, 'ReturnConsumedCapacity' => $returnConsumedCapacity, 'ReturnItemCollectionMetrics' => $returnItemCollectionMetrics];
     if ($expected !== null) {
         $args['Expected'] = $expected;
     }
     return $this->client->putItem($args);
 }
开发者ID:m6web,项目名称:aws-bundle,代码行数:23,代码来源:Client.php

示例13: regenerateID

 /**
  * Updates the current session id with a newly generated one.
  * Please refer to {@link http://php.net/session_regenerate_id} for more details.
  * @param boolean $deleteOldSession Whether to delete the old associated session file or not.
  * @since 1.1.8
  */
 public function regenerateID($deleteOldSession = false)
 {
     $oldId = session_id();
     parent::regenerateID(false);
     $newId = session_id();
     $row = $this->getData($oldId);
     if (!is_null($row)) {
         if ($deleteOldSession) {
             // Delete + Put = Update
             $this->dynamoDb->deleteItem(array('TableName' => $this->tableName, 'Key' => array('id' => array('S' => (string) $oldId))));
             $this->dynamoDb->putItem(array('TableName' => $this->tableName, 'Item' => array($this->idColumn => array('S' => (string) $newId), $this->dataColumn => $row[$this->dataColumn], $this->expireColumn => $row[$this->expireColumn])));
         } else {
             $row[$this->idColumn] = array('S' => (string) $newId);
             $this->dynamoDb->putItem(array('TableName' => $this->tableName, 'Item' => array($row)));
         }
     } else {
         $this->dynamoDb->putItem(array('TableName' => $this->tableName, 'Item' => array($this->idColumn => array('S' => $newId), $this->expireColumn => array('N' => $this->getExpireTime()))));
     }
 }
开发者ID:pythagor,项目名称:yii2-dynamodbsession,代码行数:25,代码来源:DynamoDbSession.php

示例14: putItem

 /**
  * putItem
  *
  * @param array $values
  * @param array $options
  * @param array $expected
  *
  * @return \Guzzle\Service\Resource\Model
  *
  * @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_putItem
  */
 public function putItem(array $values, array $options = array(), array $expected = array())
 {
     $args = array('TableName' => $this->_table_name, 'Item' => $this->_formatAttributes($values), '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->putItem($args);
     self::_logQuery('putItem', $args, $item);
     return $item;
 }
开发者ID:albertleao,项目名称:kettle,代码行数:30,代码来源:kettle.php

示例15: store

 /**
  * @param string $key
  * @param mixed  $value
  */
 public function store($key, $value)
 {
     $this->dynamoDbClient->putItem(['TableName' => $this->tableName, 'Item' => [$this->attribute => [$this->getVariableType($key) => (string) $key], 'status' => [$this->getVariableType($value) => (string) $value]]]);
 }
开发者ID:wadify,项目名称:store-key-client-php,代码行数:8,代码来源:Client.php


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