节点续集 mysql 转换布尔字段而不带<缓冲区 00>



我使用mysql

我尝试构建一个rest api。

我定义了一个序列化模型,

module.exports = function(sequelize, DataTypes) {
return sequelize.define('unseuil', {
id: {
autoIncrement: true,
type: DataTypes.BIGINT,
allowNull: false,
primaryKey: true
},
actif: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true
},
codeisin: {
type: DataTypes.STRING(20),
allowNull: true
},
...

我建立了2个查询。

首先

async function getListeSeuil(codeisin) {
let liste = await db.unseuil.findAll({ where: { codeisin: codeisin }, order: [
['cours', 'ASC']
], raw : true });

结果:

[
{
id: 2464,
actif: <Buffer 00>,
codeisin: 'LU1598757687',
cours: 10.45,
datecreation: 2020-07-22T11:57:52.000Z,
description: 'Resistance'
},
...

第二

async function getListeSeuil(codeisin) {
let liste = await db.unseuil.findAll({ where: { codeisin: codeisin }, order: [
['cours', 'ASC']
] });

结果:

[
unseuil {
dataValues: {
id: 2464,
actif: false,
codeisin: 'LU1598757687',
cours: 10.45,
datecreation: 2020-07-22T11:57:52.000Z,
description: 'Resistance'
},
_previousDataValues: {
id: 2464,
actif: false,
codeisin: 'LU1598757687',
cours: 10.45,
datecreation: 2020-07-22T11:57:52.000Z,
description: 'Resistance'
},
...

数据值正确

我找到了解决这个问题的办法。

我想要一个具有原始值和actif作为布尔值的数组。

好方法是什么?

我的第一个解决方案

async function getListeSeuil2(codeisin) {
let liste = await db.unseuil.findAll({ where: { codeisin: codeisin }, order: [
['cours', 'ASC']
], raw : true });
// correctif d'un bug de reconstruction des booleans.
var tab = [];
for (var element of liste)
{
tab.push(element.dataValues);
}
return tab;
}

相关内容

最新更新