我正在从mysql database
到express
rest api应用程序获取数据。使用sequelize作为ORM。
当涉及到来自MySQL的BIT(1)
值时,sequelize返回一个instance of buffer object
。
{
"id": 4,
"ProductPrice": 12.25,
"ProductQuantityOnHand": 0,
"ProductCode": "P486",
"ProductName": "FirstProduct",
"ProductDescription": null,
"ProductActive": {
"type": "Buffer",
"data": [
1
]
},
"createdAt": "2019-02-02T11:27:00.000Z",
"updatedAt": "2019-02-02T11:27:00.000Z"
}
像这里的乘积激活BIT(1)并顺序返回一个对象。
如何获得boolean value instead of an object
?
喜欢这个。
{
"id": 4,
"ProductPrice": 12.25,
"ProductQuantityOnHand": 0,
"ProductCode": "P486",
"ProductName": "FirstProduct",
"ProductDescription": null,
"ProductActive": true,
"createdAt": "2019-02-02T11:27:00.000Z",
"updatedAt": "2019-02-02T11:27:00.000Z"
}
答案 0 :(得分:1)
我可能建议您只在MySQL表中使用INT
列。假设您只存储值0和1,这些相同的值应显示在ORM /应用程序层中。
由于值0
在JavaScipt中为“ falsy”,因此在逻辑上其行为与false
相同,而对于1
则相反,这是“真实的”。 / p>