我第一次直接使用 Dynamo,在本地的玩具项目中。我正在尝试创建由条件表达式保护的记录 - 如果用户名(范围键)或uniqueId(哈希键)已经存在,则失败:。但是,当我放置具有相同用户名的记录时,我不会遇到冲突 - 并且对表的扫描证实了这一点。我正在使用localstack(本地AWS模拟),如果这有所作为的话。"attribute_not_exists(UserId) and attribute_not_exists(Username)"
问题:
我应该使用事务还是其他抽象?
我是否在表设置中构造了错误的键(请参阅 q 的底部)?
是否需要在条件中指定密钥的类型?
以下是创建记录的逻辑:
userID := GenerateUniqueID()
record := UserCredentialsRecord{
UserID: userID,
Username: username,
Password: base64.StdEncoding.EncodeToString(hashedPassword),
Salt: base64.StdEncoding.EncodeToString(salt),
Email: email,
AccountCreatedTS: time.Now().Unix(),
}
...
input := &dynamodb.PutItemInput{
Item: av,
TableName: aws.String(userCredentialsTableName),
ConditionExpression: aws.String("attribute_not_exists(UserId) and attribute_not_exists(Username)"),
}
...
_, err = session.PutItem(input)
if err != nil {
fmt.Println("Got error calling PutItem:", err.Error())
}
开满天机
HUH函数
相关分类