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



有没有一种方法可以通过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,
}
);

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

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