public function testGetPartial() { $context = new Context\Get(); $context->setAttributesToGet(array('id')); $id = intval(getenv('ITEM_ID')); $item = $this->conn->get(getenv('DY_TABLE'), $id, null, $context); $this->assertInstanceOf('\\Riverline\\DynamoDB\\Item', $item); $this->assertSame($id, $item['id']); $this->assertEmpty($item['name']); }
/** * Get an item via the get_item call * @param string $table The item table * @param mixed $hash The primary hash key * @param mixed|null $range The primary range key * @param Context\Get|null $context The call context * @return Item|null */ public function get($table, $hash, $range = null, Context\Get $context = null) { if (null !== $this->logger) { $this->log('Get on table ' . $table); } // Primary key $hash = new Attribute($hash); $parameters = array('TableName' => $table, 'Key' => array('HashKeyElement' => $hash->getForDynamoDB())); // Range key if (null !== $range) { $range = new Attribute($range); $parameters['Key']['RangeKeyElement'] = $range->getForDynamoDB(); } if (null !== $context) { $parameters += $context->getForDynamoDB(); } if (null !== $this->logger) { $this->log('Get request paramaters : ' . print_r($parameters, true), Logger::DEBUG); } $response = $this->connector->getItem($parameters); if (null !== $this->logger) { $this->log('Get request response : ' . print_r($response, true), Logger::DEBUG); } $this->addConsumedReadUnits($table, floatval($response['ConsumedCapacityUnits'])); if (isset($response['Item'])) { $item = new Item($table); $item->populateFromDynamoDB($response['Item']); return $item; } else { if (null !== $this->logger) { $this->log('Didn\'t find item'); } return null; } }