Sequelize,findAll,属性不能重命名列
Sequelize,findAll, attributes can not rename column
我的Table数据:
Mytable(id,col1,col2,time)
有数据
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']
-> 先在里面 {}
使用 findAll 和
const convertedData = await rows.map(arrObj => {
return {
newname: reqbody.olddata
}})
我的Table数据:
Mytable(id,col1,col2,time)
有数据
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']
-> 先在里面 {}
使用 findAll 和
const convertedData = await rows.map(arrObj => {
return {
newname: reqbody.olddata
}})