gpt4 book ai didi

node.js - 在 sequelize.query 中插入,然后返回插入的行

转载 作者:行者123 更新时间:2023-12-03 22:22:37 24 4
gpt4 key购买 nike

有没有办法在 sequelize 中通过原始插入查询返回插入的行?returning 选项不会改变任何返回值。返回插入行的计数和空数组而不是插入的行:[ [], 1 ]

let contato = await sequelize.query(
'INSERT INTO public.contato(nome, telefone, id_empresa, id_status) VALUES ($nome, $telefone, $id_empresa, $id_status);',
{
bind: {
nome: form.nome,
telefone: form.telefone,
id_empresa: filaChat.id_empresa,
id_status: 1,
},
type: QueryTypes.INSERT,
returning: true,
}
);

最佳答案

对于 postgres,您需要在原始查询中包含 RETURNING id

INSERT INTO public.contato(nome, telefone, id_empresa, id_status)
VALUES ($nome, $telefone, $id_empresa, $id_status)
RETURNING id;

关于node.js - 在 sequelize.query 中插入,然后返回插入的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64714960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com