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

王林
Release: 2024-02-09 12:54:08
forward
367 people have browsed it

使用 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]
    }
 },
Copy after login

The typical implementation in gosdk is:

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

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"]
}
Copy after login

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!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template