[英]how to get id of last inserted row in RDS Aurora in GraphQL mutation
I've a table with (id, price). 我有一张桌子(编号,价格)。 id is autoincremented.
id是自动递增的。 I want to return the id and full data of last inserted row.
我想返回最后插入的行的ID和完整数据。
Resolver: 解析器:
{
"version": "2018-05-29",
"statements": [
"insert into notes (price) VALUES (100)",
"select * from notes WHERE id = $id"
]
}
How can I find the id of last inserted row. 如何找到最后插入的行的ID。 Second query of course will not work here as id is not known.
第二个查询当然不会在这里工作,因为id未知。
Does SELECT LAST_INSERT_ID(); SELECT LAST_INSERT_ID(); work well in serverless context?
在无服务器环境下工作良好? How to store that variable and run third query?
如何存储该变量并运行第三个查询?
I was running into the same issue. 我遇到了同样的问题。 So far, this seems to work for us:
到目前为止,这似乎对我们有用:
{
"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.