gpt4 book ai didi

javascript - Sequelize : Use query results as table for selectQuery

转载 作者:行者123 更新时间:2023-11-28 03:59:20 25 4
gpt4 key购买 nike

是否可以将查询结果用作sequelize 查询生成器中另一个选择的表?这是我试图生成的 SQL:

UPDATE target 
SET fk1_id = '1'
WHERE id NOT IN
(SELECT id
FROM (
SELECT id
FROM target
WHERE fk1_id = 1 AND fk2_id = 2
) AS inner_target )
AND fk1_id IS NULL AND fk2_id = '2' LIMIT 1

我正在尝试通过以下方式实现这一目标:

const innerSelect = 
sequelize.dialect.QueryGenerator.selectQuery('target', {
attributes: ['fk1_id'],
where: {
fk1_id: fk1_id,
fk2_id: fk2_id,
},
}).slice(0, -1);

const selectAs = sequelize.dialect.QueryGenerator.selectQuery(
sequelize.literal(`${innerSelect}`), {
attributes: ['id'],
}).slice(0, -1);

但是,我收到一条错误消息:

"message": "Table 'db.undefined' doesn't exist"
"name": "SequelizeDatabaseError"
"code": "ER_NO_SUCH_TABLE"

并且内部选择试图从未定义

中进行选择

如有任何建议,我们将不胜感激!

最佳答案

根据该错误,您尚未创建正在查询的表。

关于javascript - Sequelize : Use query results as table for selectQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47269184/

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