![](/img/trans.png)
[英]Using react-apollo (GraphQL) to do an insert mutation, how do I get the inserted id for the local store update?
[英]how to get id of last inserted row in RDS Aurora in GraphQL mutation
我有一张桌子(编号,价格)。 id是自动递增的。 我想返回最后插入的行的ID和完整数据。
解析器:
{
"version": "2018-05-29",
"statements": [
"insert into notes (price) VALUES (100)",
"select * from notes WHERE id = $id"
]
}
如何找到最后插入的行的ID。 第二个查询当然不会在这里工作,因为id未知。
SELECT LAST_INSERT_ID(); 在无服务器环境下工作良好? 如何存储该变量并运行第三个查询?
我遇到了同样的问题。 到目前为止,这似乎对我们有用:
{
"version": "2018-05-29",
"statements": [
"INSERT INTO customer_addresses (`id`, `customerid`, `firstname`, `lastname`) VALUES (NULL, :CUSTOMERID, :FIRSTNAME, :LASTNAME)",
"SELECT * FROM customer_addresses WHERE id = LAST_INSERT_ID()"
],
"variableMap": {
":CUSTOMERID": $context.args.customerid,
":FIRSTNAME": "$context.args.input.firstname",
":LASTNAME": "$context.args.input.lastname"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.