gpt4 book ai didi

amazon-web-services - 如何在 AppSync 解析器中运行多个 SQL 语句?

转载 作者:行者123 更新时间:2023-12-05 07:25:01 25 4
gpt4 key购买 nike

我有两个表,cutsholds。为了响应我的应用程序中的事件,我希望能够将值从具有给定 idhold 条目移动到 cuts table 。天真的方法是先执行 INSERT,然后执行 DELETE

如何在 AppSync 解析器中运行多个 sql 语句以获得该结果?我尝试了以下方法(将 sql 替换为 statements 并将其转换为数组)但没有成功。

{
"version" : "2017-02-28",
"operation": "Invoke",

#set($id = $util.autoId())

"payload": {
"statements": [
"INSERT INTO cuts (id, rollId, length, reason, notes, orderId) SELECT '$id', rollId, length, reason, notes, orderId FROM holds WHERE id=:ID",
"DELETE FROM holds WHERE id=:ID"
],
"variableMapping": {
":ID": "$context.arguments.id"
},
"responseSQL": "SELECT * FROM cuts WHERE id = '$id'"
}

最佳答案

如果您正在使用此处找到的“通过 AWS Lambda 使用 Amazon Aurora 作为数据源的 AWS AppSync”https://github.com/aws-samples/aws-appsync-rds-aurora-sample , 你将无法在 sql 字段中发送多个语句

如果您使用 AWS AppSync 与 Aurora Serverless Data API 集成,您可以在一个语句数组中传递最多 2 个语句,如下例所示:

{
"version": "2018-05-29",
"statements": [
"select * from Pets WHERE id='$ctx.args.input.id'",
"delete from Pets WHERE id='$ctx.args.input.id'"
]
}

关于amazon-web-services - 如何在 AppSync 解析器中运行多个 SQL 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55105979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com