Dynamodb.ScanInput - 不能使用 'expr.Names()'(类型 map[string]*string)作为类型 map[string]string
Dynamodb.ScanInput - Cannot use 'expr.Names()' (type map[string]*string) as the type map[string]string
我需要使用过滤在 dynamodb 中扫描我的 table。我在网上找到了很多例子,但是当我尝试使用它们时,我总是遇到同样的错误。
filter := expression.Name("CreatedDate").LessThan(expression.Value(time.Now().UTC()))
expr, err := expression.NewBuilder().WithFilter(filter).Build()
if err != nil {
panic(err)
}
out, err := svc.Scan(context.TODO(), &dynamodb.ScanInput{
TableName: aws.String(tableName),
FilterExpression: expr.Filter(),
ExpressionAttributeNames: expr.Names(),
ExpressionAttributeValues: expr.Values(),
})
if err != nil {
panic(err)
}
在 expr.Names() 和 expr.Values() 上出现错误
Cannot use 'expr.Names()' (type map[string]*string) as the type map[string]string
提前致谢!
你没有说明是编译错误还是在panic中显示。
无论如何,expr.Names()
expr.Values()
将是 map[string]*string
如果使用 expression
来自 aws-sdk-go
除了 aws-sdk-go-v2
.
修复
从
更新您的导入
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/expression"
如下所示
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
我需要使用过滤在 dynamodb 中扫描我的 table。我在网上找到了很多例子,但是当我尝试使用它们时,我总是遇到同样的错误。
filter := expression.Name("CreatedDate").LessThan(expression.Value(time.Now().UTC()))
expr, err := expression.NewBuilder().WithFilter(filter).Build()
if err != nil {
panic(err)
}
out, err := svc.Scan(context.TODO(), &dynamodb.ScanInput{
TableName: aws.String(tableName),
FilterExpression: expr.Filter(),
ExpressionAttributeNames: expr.Names(),
ExpressionAttributeValues: expr.Values(),
})
if err != nil {
panic(err)
}
在 expr.Names() 和 expr.Values() 上出现错误
Cannot use 'expr.Names()' (type map[string]*string) as the type map[string]string
提前致谢!
你没有说明是编译错误还是在panic中显示。
无论如何,expr.Names()
expr.Values()
将是 map[string]*string
如果使用 expression
来自 aws-sdk-go
除了 aws-sdk-go-v2
.
修复
从
更新您的导入"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/expression"
如下所示
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"