putItem method
- required Map<
String, AttributeValue> item, - required String tableName,
- Map<
String, ExpectedAttributeValue> ? expected, - ReturnValue? returnValues,
Creates a new item, or replaces an old item with a new item (including all the attributes).
If an item already exists in the specified table with the same primary key, the new item completely replaces the existing item. You can perform a conditional put (insert a new item if one with the specified primary key doesn't exist), or replace an existing item if it has certain 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 put an item. Allowed characters
are a-z
, A-Z
, 0-9
, _
(underscore), -
(hyphen) and .
(period).
Implementation
Future<PutItemOutput> putItem({
required Map<String, AttributeValue> item,
required String tableName,
Map<String, ExpectedAttributeValue>? expected,
ReturnValue? returnValues,
}) async {
ArgumentError.checkNotNull(item, 'item');
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.PutItem'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'Item': item,
'TableName': tableName,
if (expected != null) 'Expected': expected,
if (returnValues != null) 'ReturnValues': returnValues.toValue(),
},
);
return PutItemOutput.fromJson(jsonResponse.body);
}