updateItem method
Future<UpdateItemOutput>
updateItem({
- required Map<
String, AttributeValueUpdate> attributeUpdates, - required Key key,
- required String tableName,
- Map<
String, ExpectedAttributeValue> ? expected, - ReturnValue? returnValues,
Edits an existing item's attributes.
You can 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).
May throw ConditionalCheckFailedException. May throw ProvisionedThroughputExceededException. May throw ResourceNotFoundException. May throw LimitExceededException. May throw RequestLimitExceeded. May throw InternalServerError.
Parameter tableName
:
The name of the table in which you want to update an item. Allowed
characters are a-z
, A-Z
, 0-9
,
_
(underscore), -
(hyphen) and .
(period).
Implementation
Future<UpdateItemOutput> updateItem({
required Map<String, AttributeValueUpdate> attributeUpdates,
required Key key,
required String tableName,
Map<String, ExpectedAttributeValue>? expected,
ReturnValue? returnValues,
}) async {
ArgumentError.checkNotNull(attributeUpdates, 'attributeUpdates');
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.UpdateItem'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'AttributeUpdates': attributeUpdates,
'Key': key,
'TableName': tableName,
if (expected != null) 'Expected': expected,
if (returnValues != null) 'ReturnValues': returnValues.toValue(),
},
);
return UpdateItemOutput.fromJson(jsonResponse.body);
}