gpt4 book ai didi

typescript - Sequelize 动态选择属性?作品?

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

面临一个问题 - 是否真的可以将动态选择属性传递给 FindAll 方法?它不起作用,因为它没有得到认可。

selectAttributes= "'x_name','y_name','z_name','start_z'"; //prepare this dynamically
groupBy = ['x_name','y_name','z_name','start_z','start_z']
const results = await XX.findAll({
group:groupBy,
attributes:['x_name','y_name','z_name','start_z','start_z',
[Sequelize.fn(Constants.SEQUELIZE_SUM_FUNCTION,
Sequelize.col(obj.metrics)),obj.metrics]],

where:result.where , //I have this built dynamically which works great
order: result.order,//I have this built dynamically which works great

});

//上面的代码有效并获取select中的所有列。但我想与 group 和 where 以及 order by 一起动态传递列;我在 where/orderby/group by 上取得了成功,但没有选择属性。我正在制作一个字符串并将其作为选择属性传递,但它无法识别它并在上面的代码中仅返回 SUM 列。

如何概括 FindALL 的 SELECT 属性?

最佳答案

可能这会帮助其他希望构建动态选择属性的人。
selectAttributes= build your array here dynamically //prepare this dynamically
groupBy = ['x_name','y_name','z_name','start_z','start_z']

const results = await XX.findAll({
group:groupBy,

attributes:[...selectAttributes, [Sequelize.fn(Constants.SEQUELIZE_SUM_FUNCTION, Sequelize.col(obj.tasks)),obj.tasks]],
where:result.where , //I have this built dynamically which works great
order: result.order,//I have this built dynamically which works great
});

关于typescript - Sequelize 动态选择属性?作品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60935451/

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