我可以通过sequelize insertOrUpdate获取新插入的ID吗?

时间:2018-08-25 05:18:57

标签: node.js sequelize.js

如何获得带有以下续集的新插入的ID?当前返回一个布尔值。

var method = "post";
var path = "cookie.php";
var form = document.createElement("form")
form.setAttribute("method",method);
form.setAttribute("path",path)
var hiddenform = document.createElement("input")
hiddenform.setAttribute("type","hidden")
hiddenform.setAttribute("id","hiddeninputusername")
hiddenform.setAttribute("value",cookieusername)
form.appendChild(hiddenform);
var hiddenforms = document.createElement("input")
hiddenforms.setAttribute("type","hidden")
hiddenforms.setAttribute("id","hiddeninputusername")
hiddenforms.setAttribute("value",cookiepassword)
form.appendChild(hiddenforms)
form.submit()

1 个答案:

答案 0 :(得分:0)

您可以使用returning : true(取回自动生成的值),但这仅适用于Postgres

exports.update = async note => entityChildModel
                                .insertOrUpdate(note , { returning : true }) // <--- HERE
                                .catch(e => 'Error');

更多详细信息: DO READ