Created
July 17, 2020 12:36
-
-
Save simonpainter/d0867ed32c051cb1877d4919bee9f8ad to your computer and use it in GitHub Desktop.
Inserting unique value into DynamoDB list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$marshaler = new Marshaler(); | |
$UpdateExpression = " | |
SET #subscribers = list_append(if_not_exists(#subscribers, :empty_list), :subscriber) | |
"; | |
$ConditionExpression = " | |
NOT contains (#subscribers,:subscriberStr) | |
"; | |
$ExpressionAttributeNames = [ | |
"#subscribers" => "subscribers" | |
]; | |
$ExpressionAttributeValues = $marshaler->marshalJson(' | |
{ | |
":subscriber" : ['.$subscriber.'], | |
":subscriberStr" : '.$subscriber.', | |
":empty_list" :[] | |
} | |
'); | |
$tableName = 'publisherRelationships'; | |
$key = $marshaler->marshalJson(' | |
{ | |
"publisher": '.$publisher.' | |
} | |
'); | |
$params = [ | |
'TableName' => $tableName, | |
'Key' => $key, | |
'UpdateExpression' => $UpdateExpression, | |
'ConditionExpression' => $ConditionExpression, | |
'ExpressionAttributeNames' => $ExpressionAttributeNames, | |
'ExpressionAttributeValues' => $ExpressionAttributeValues | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment