DynamoDB ConditionExpression 如果结果值为正?
DynamoDB ConditionExpression if resulting value is positive?
我正在编写一个具有临界点功能的应用程序。我想进行条件更新,仅当用户钱包的结果值为 0 或更高时才执行。如果值为负,则不应进行更新。
该函数在没有条件表达式的情况下工作,但当我添加它时,它会中断。
ConditionExpression: 'teleUser.wallet.points -:a > -1',
在上面的行中 :a
是一个传入的整数。我会 post 下面的上下文,但上面一行是我的问题所在。
返回的错误是ValidationException: Invalid ConditionExpression: Syntax error; token: "-", near: "points -:a"
.
上下文的完整功能:
function removeFromWallet(msg, amount) {
console.log("remove");
let params = {
TableName: tableName,
Key: {"id": msg.from.id},
UpdateExpression: 'set teleUser.wallet.points = teleUser.wallet.points -:a',
ExpressionAttributeValues:{
":a": parseInt(amount)
},
ConditionExpression: 'teleUser.wallet.points -:a > -1',
ReturnValues:"UPDATED_NEW"
};
docClient.update(params, function(err, data) {
if (err) {
console.log(err);
} else {
const { Items } = data;
console.log(data.Attributes.teleUser.wallet.points);
addToWallet(msg, amount);
}
});
}
您无法在 ConditionExpression
(see grammar for ConditionExpression)
中执行计算
condition-expression ::=
operand comparator operand
| operand BETWEEN operand AND operand
| operand IN ( operand (',' operand (, ...) ))
| function
| condition AND condition
| condition OR condition
| NOT condition
| ( condition )
comparator ::=
=
| <>
| <
| <=
| >
| >=
function ::=
attribute_exists (path)
| attribute_not_exists (path)
| attribute_type (path, type)
| begins_with (path, substr)
| contains (path, operand)
| size (path)
您可以在 ExpressionAttributeValues
中执行计算,但在这种特殊情况下,您可能必须使用 teleUser.wallet.points >= :a
,因为列值在 ExpressionAttributeValues
[=16= 中不可用]
我正在编写一个具有临界点功能的应用程序。我想进行条件更新,仅当用户钱包的结果值为 0 或更高时才执行。如果值为负,则不应进行更新。
该函数在没有条件表达式的情况下工作,但当我添加它时,它会中断。
ConditionExpression: 'teleUser.wallet.points -:a > -1',
在上面的行中 :a
是一个传入的整数。我会 post 下面的上下文,但上面一行是我的问题所在。
返回的错误是ValidationException: Invalid ConditionExpression: Syntax error; token: "-", near: "points -:a"
.
上下文的完整功能:
function removeFromWallet(msg, amount) {
console.log("remove");
let params = {
TableName: tableName,
Key: {"id": msg.from.id},
UpdateExpression: 'set teleUser.wallet.points = teleUser.wallet.points -:a',
ExpressionAttributeValues:{
":a": parseInt(amount)
},
ConditionExpression: 'teleUser.wallet.points -:a > -1',
ReturnValues:"UPDATED_NEW"
};
docClient.update(params, function(err, data) {
if (err) {
console.log(err);
} else {
const { Items } = data;
console.log(data.Attributes.teleUser.wallet.points);
addToWallet(msg, amount);
}
});
}
您无法在 ConditionExpression
(see grammar for ConditionExpression)
condition-expression ::=
operand comparator operand
| operand BETWEEN operand AND operand
| operand IN ( operand (',' operand (, ...) ))
| function
| condition AND condition
| condition OR condition
| NOT condition
| ( condition )
comparator ::=
=
| <>
| <
| <=
| >
| >=
function ::=
attribute_exists (path)
| attribute_not_exists (path)
| attribute_type (path, type)
| begins_with (path, substr)
| contains (path, operand)
| size (path)
您可以在 ExpressionAttributeValues
中执行计算,但在这种特殊情况下,您可能必须使用 teleUser.wallet.points >= :a
,因为列值在 ExpressionAttributeValues
[=16= 中不可用]