简体   繁体   中英

how to get id of last inserted row in RDS Aurora in GraphQL mutation

I've a table with (id, price). id is autoincremented. I want to return the id and full data of last inserted row.

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. Second query of course will not work here as id is not known.

Does 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"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM