getItem method
Retrieves a set of Attributes for an item that matches the primary key.
The GetItem
operation provides an eventually-consistent read
by default. If eventually-consistent reads are not acceptable for your
application, use ConsistentRead
. Although this operation
might take longer than a standard read, it always returns the last updated
value.
May throw ProvisionedThroughputExceededException. May throw ResourceNotFoundException. May throw RequestLimitExceeded. May throw InternalServerError.
Parameter tableName
:
The name of the table in which you want to get an item. Allowed characters
are a-z
, A-Z
, 0-9
, _
(underscore), -
(hyphen) and .
(period).
Implementation
Future<GetItemOutput> getItem({
required Key key,
required String tableName,
List<String>? attributesToGet,
bool? consistentRead,
}) async {
ArgumentError.checkNotNull(key, 'key');
ArgumentError.checkNotNull(tableName, 'tableName');
_s.validateStringLength(
'tableName',
tableName,
3,
255,
isRequired: true,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'DynamoDB_20111205.GetItem'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'Key': key,
'TableName': tableName,
if (attributesToGet != null) 'AttributesToGet': attributesToGet,
if (consistentRead != null) 'ConsistentRead': consistentRead,
},
);
return GetItemOutput.fromJson(jsonResponse.body);
}