Home  >  Article  >  Backend Development  >  How to declare ValueBuilder object as StringSet when executing UpdateItem in Dynamodb using gosdk?

How to declare ValueBuilder object as StringSet when executing UpdateItem in Dynamodb using gosdk?

王林
王林forward
2024-02-09 12:54:08333browse

使用 gosdk 在 Dynamodb 中执行 UpdateItem 时如何将 ValueBuilder 对象声明为 StringSet?

php editor Apple here introduces a method of using gosdk to declare the ValueBuilder object as a StringSet when executing UpdateItem in Dynamodb. In Dynamodb, StringSet is a data type used to store a collection of strings. By using the ValueBuilder object, we can easily construct this StringSet to update the data in Dynamodb. Next, we will introduce in detail how to use gosdk to implement this process.

Question content

NOTE: Might look like a duplicate of this but it's different because I need to do this via golang and this is in js.

I want to perform the following operations on the dynamodb project in gosdk:

updateexpression: 'add socialaccounts :socialaccountid',
 expressionattributevalues: {
   ':socialaccountid': {
      'ss': [socialaccountid]
    }
 },

The typical implementation in gosdk is:

expression.add(expression.name("socialaccounts"), expression.value([]string{"socialaccountid"}))

However, the sdk does not treat the string array as a ss(stringset) type, but as a l(list) type.

Logged errors:

65bcdb1af85f

I can't find any functionality in the documentation that specifies how types are mentioned.

Can anyone help?

Why I want to do this:

  1. I want it to work even if the attribute socialaccounts does not exist.
  2. I don't want to use the set operation with list_append as this may introduce duplicate elements.

Solution

If you need to specify the type, please use dynamodb.attributevalue:

65bcdb27f61a

Output:

{
  SS: ["socialAccountId"]
}

The above is the detailed content of How to declare ValueBuilder object as StringSet when executing UpdateItem in Dynamodb using gosdk?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete