返回数据数组而不是字典-Sequelize

时间:2018-10-15 14:10:56

标签: javascript node.js sequelize.js

我需要发布数据(例如数组),但我总是这样发送数据:

{
    "books": [
        {
            "id": 19,
            "name": "Král Lávra",
            "author": "Karel Havlíček Borovský",
            "yearOfRelease": "1920",
            "price": "120",
            "SubjectId": 1,
            "UserId": 2,
            "SchoolId": 1
        },
      ]
}

我想要这样显示结果:

[
        {
            "id": 19,
            "name": "Král Lávra",
            "author": "Karel Havlíček Borovský",
            "yearOfRelease": "1920",
            "price": "120",
            "SubjectId": 1,
            "UserId": 2,
            "SchoolId": 1
        },
]

我使用sequelize连接数据库MySQL。这是我的findAll书的代码:

let books = await ctx.db.Book.findAll({
        where: {
            UserId: id
        },
    })

然后我只发布到

ctx.body=  {
   books
}

感谢您的回复。

0 个答案:

没有答案