node.js - Sequelize,findAll,属性不能重命名列
问题描述
我的表数据:
Mytable(id,col1,col2,时间)
有数据
Mytable("1","val1","val2","time")
我通过这段代码获取数据:
async function getData() {
const mytables = await Mytable.findAll(
{ where: { id: othervalue }},
{ attributes: ['col1',['id', 'newnameid'],'newnamecol1']}
);
console.log(JSON.stringifty(mytables));
}
getData();
我只想要这样的数据:
[ {'newnameid':'1','newnamecol1':'val1'} ]
但我得到了这个:
[ {'id':'1','col1':'val1','col2':'val2,'time':'time''} ]
嗯,这段代码可能有什么问题?
解决方案
async function getData() {
const mytables = await Mytable.findAll(
{
where: { id: othervalue },
attributes: ['col1',['id', 'newnameid'],'newnamecol1']
},
);
console.log(JSON.stringifty(mytables));
}
getData();
更新:
attributes: ['col1',['id', 'newnameid'],'newnamecol1']
-> 内部优先{}
推荐阅读
- java - 替换硬编码凭据
- vba - In Word 2016 embedded Excel tables can't be scaled via VBA
- c# - 解决接口的多重实现
- informix - ifxnjs 不支持 NODE_MODULE_VERSION 64
- tfs - 给出“MsBuild.exe”的 SonarScanner 在 TFS 2018 上未被识别为内部或外部命令
- java - Hazelcast-wm 节点如何在 P2P 模式下找到彼此?
- java - 将多个文件添加到 Spring mime 消息时出错
- python - 将 tensorflow 导入为 tf 时导入 TensorFlow 时出错
- prolog - 对原子的子类进行分类的序言错误
- server - https://dnsflagday.net/ 报告 edns512tcp=timeout