简体   繁体   English

如何在GraphQL突变中获取RDS Aurora中最后插入的行的ID

[英]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.

相关问题 使用react-apollo(GraphQL)进行插入突变,如何获取本地商店更新的插入ID? - Using react-apollo (GraphQL) to do an insert mutation, how do I get the inserted id for the local store update? id字段上的GraphQL突变 - GraphQL mutation on id field 如何在 Nestjs + Graphql Mutation Args 中定义 ID 类型? - How to define ID type in Nestjs + Graphql Mutation Args? GraphQL - 如何在查询多个突变期间检索先前突变的 id - GraphQL - How retrieve id of previous mutation, during query of multiple mutations 如何在反应更新突变中访问object.id,graphql与棱镜 - How to access object.id in update mutation in react, graphql with prisma 如何在 GraphQL 中执行突变? - How to execute a mutation in GraphQL? 如何在graphql中获取最后3个元素 - How in graphql get last 3 element Apollo GraphQL-如何从缓存存储中获取通过突变记录的数据? - Apollo GraphQL - How to get data recorded by mutation from the cache store? 如何获取所有 graphql 模式查询、变异、订阅 - How to get all graphql schema query, mutation, subscribe 如何从生成的模式中获取简单的 graphql 突变查询? - How to get simple graphql mutation query from generated schema?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM